<!DOCTYPE HTML>
<html lang="en-US" manifest="../manifest.appcache">
    
    <head>
        
        <meta charset="UTF-8">
        <title>创建并监视异常区域 | Android Training Course in Chinese</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 0.5.2">
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    
    
    <meta name="author" content="kesenhoo">
    
    
    <link rel="next" href="../location/activity-recognition.html" />
    
    
    <link rel="prev" href="../location/display-address.html" />
    

        
    </head>
    <body>
        
        
<link rel="stylesheet" href="../gitbook/style.css">


        
    <div class="book" data-github="kesenhoo/android-training-course-in-chinese" data-level="10.4" data-basepath=".." data-revision="1405874281425">
    <div class="book-header">
    <!-- Actions Left -->
    <a href="#" class="btn pull-left toggle-summary" aria-label="Toggle summary"><i class="fa fa-align-justify"></i></a>
    
    <a href="https://github.com/kesenhoo/android-training-course-in-chinese" target="_blank" class="btn pull-left home-bookmark" aria-label="GitHub home"><i class="fa fa-bookmark-o"></i></a>
    
    <a href="#" class="btn pull-left toggle-search" aria-label="Toggle search"><i class="fa fa-search"></i></a>
    <span id="font-settings-wrapper">
        <a href="#" class="btn pull-left toggle-font-settings" aria-label="Toggle font settings"><i class="fa fa-font"></i>
        </a>
        <div class="dropdown-menu font-settings">
    <div class="dropdown-caret">
        <span class="caret-outer"></span>
        <span class="caret-inner"></span>
    </div>

    <div class="btn-group btn-block">
        <button id="reduce-font-size" class="btn btn-default">A</button>
        <button id="enlarge-font-size" class="btn btn-default">A</button>
    </div>

    <ul class="list-group font-family-list">
        <li class="list-group-item" data-font="0">Serif</li>
        <li class="list-group-item" data-font="1">Sans</li>
    </ul>

    <div class="btn-group btn-group-xs btn-block color-theme-list">
        <button type="button" class="btn btn-default" id="color-theme-preview-0" data-theme="0">White</button>
        <button type="button" class="btn btn-default" id="color-theme-preview-1" data-theme="1">Sepia</button>
        <button type="button" class="btn btn-default" id="color-theme-preview-2" data-theme="2">Night</button>
    </div>
</div>

    </span>

    <!-- Actions Right -->
    
    <a href="#" target="_blank" class="btn pull-right google-plus-sharing-link sharing-link" data-sharing="google-plus" aria-label="Share on Google Plus"><i class="fa fa-google-plus"></i></a>
    
    
    <a href="#" target="_blank" class="btn pull-right facebook-sharing-link sharing-link" data-sharing="facebook" aria-label="Share on Facebook"><i class="fa fa-facebook"></i></a>
    
    
    <a href="#" target="_blank" class="btn pull-right twitter-sharing-link sharing-link" data-sharing="twitter" aria-label="Share on Twitter"><i class="fa fa-twitter"></i></a>
    

    
    <a href="https://github.com/kesenhoo/android-training-course-in-chinese/stargazers" target="_blank" class="btn pull-right count-star hidden-xs"><i class="fa fa-star-o"></i> Star (<span>-</span>)</a>
    <a href="https://github.com/kesenhoo/android-training-course-in-chinese/watchers" target="_blank" class="btn pull-right count-watch hidden-xs"><i class="fa fa-eye"></i> Watch (<span>-</span>)</a>
    

    <!-- Title -->
    <h1>
        <i class="fa fa-spinner fa-spin"></i>
        <a href="../" >Android Training Course in Chinese</a>
    </h1>
</div>

    

<div class="book-summary">
    <div class="book-search">
        <input type="text" placeholder="Search" class="form-control" />
    </div>
    <ul class="summary">
        
        
        
        <li>
            <a href="https://github.com/kesenhoo" target="blank" class="author-link">About the author</a>
        </li>
        

        
        
        <li>
            <a href="https://github.com/kesenhoo/android-training-course-in-chinese/issues" target="blank"class="issues-link">Questions and Issues</a>
        </li>
        

        
        
        <li>
            <a href="https://github.com/kesenhoo/android-training-course-in-chinese/edit/master/location/geofencing.md" target="blank" class="contribute-link">Edit and Contribute</a>
        </li>
        

        
        <li class="divider"></li>
        

        <li data-level="0" data-path="index.html">
            <a href="../"><i class="fa fa-check"></i> Introduction</a>
        </li>
        
    
        <li class="chapter " data-level="1" data-path="index.html">
            
            <a href="../index.html">
                <i class="fa fa-check"></i> <b>1.</b> 序言
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="2" data-path="basics/index.html">
            
            <a href="../basics/index.html">
                <i class="fa fa-check"></i> <b>2.</b> 从这里开始
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="basics/firstapp/index.html">
            
            <a href="../basics/firstapp/index.html">
                <i class="fa fa-check"></i> <b>2.1.</b> 建立你的第一个App
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.1" data-path="basics/firstapp/creating-project.html">
            
            <a href="../basics/firstapp/creating-project.html">
                <i class="fa fa-check"></i> <b>2.1.1.</b> 创建一个Android项目
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.1.2" data-path="basics/firstapp/running-app.html">
            
            <a href="../basics/firstapp/running-app.html">
                <i class="fa fa-check"></i> <b>2.1.2.</b> 执行你的程序
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.1.3" data-path="basics/firstapp/building-ui.html">
            
            <a href="../basics/firstapp/building-ui.html">
                <i class="fa fa-check"></i> <b>2.1.3.</b> 建立一个简单的用户界面
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.1.4" data-path="basics/firstapp/starting-activity.html">
            
            <a href="../basics/firstapp/starting-activity.html">
                <i class="fa fa-check"></i> <b>2.1.4.</b> 启动另外的Activity
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="basics/actionbar/index.html">
            
            <a href="../basics/actionbar/index.html">
                <i class="fa fa-check"></i> <b>2.2.</b> 添加ActionBar
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1" data-path="basics/actionbar/setting-up.html">
            
            <a href="../basics/actionbar/setting-up.html">
                <i class="fa fa-check"></i> <b>2.2.1.</b> 建立ActionBar
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2.2" data-path="basics/actionbar/adding-buttons.html">
            
            <a href="../basics/actionbar/adding-buttons.html">
                <i class="fa fa-check"></i> <b>2.2.2.</b> 添加Action按钮
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2.3" data-path="basics/actionbar/styling.html">
            
            <a href="../basics/actionbar/styling.html">
                <i class="fa fa-check"></i> <b>2.2.3.</b> ActionBar的风格化
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2.4" data-path="basics/actionbar/overlaying.html">
            
            <a href="../basics/actionbar/overlaying.html">
                <i class="fa fa-check"></i> <b>2.2.4.</b> ActionBar的覆盖层叠
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="basics/supporting-devices/index.html">
            
            <a href="../basics/supporting-devices/index.html">
                <i class="fa fa-check"></i> <b>2.3.</b> 兼容不同的设备
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.3.1" data-path="basics/supporting-devices/languages.html">
            
            <a href="../basics/supporting-devices/languages.html">
                <i class="fa fa-check"></i> <b>2.3.1.</b> 适配不同的语言
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3.2" data-path="basics/supporting-devices/screens.html">
            
            <a href="../basics/supporting-devices/screens.html">
                <i class="fa fa-check"></i> <b>2.3.2.</b> 适配不同的屏幕
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3.3" data-path="basics/supporting-devices/platforms.html">
            
            <a href="../basics/supporting-devices/platforms.html">
                <i class="fa fa-check"></i> <b>2.3.3.</b> 适配不同的系统版本
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="basics/activity-lifecycle/index.html">
            
            <a href="../basics/activity-lifecycle/index.html">
                <i class="fa fa-check"></i> <b>2.4.</b> 管理Activity的生命周期
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="basics/activity-lifecycle/starting.html">
            
            <a href="../basics/activity-lifecycle/starting.html">
                <i class="fa fa-check"></i> <b>2.4.1.</b> 启动与销毁Activity
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4.2" data-path="basics/activity-lifecycle/pausing.html">
            
            <a href="../basics/activity-lifecycle/pausing.html">
                <i class="fa fa-check"></i> <b>2.4.2.</b> 暂停与恢复Activity
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4.3" data-path="basics/activity-lifecycle/stopping.html">
            
            <a href="../basics/activity-lifecycle/stopping.html">
                <i class="fa fa-check"></i> <b>2.4.3.</b> 停止与重启Activity
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4.4" data-path="basics/activity-lifecycle/recreating.html">
            
            <a href="../basics/activity-lifecycle/recreating.html">
                <i class="fa fa-check"></i> <b>2.4.4.</b> 重新创建Activity
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="basics/fragments/index.html">
            
            <a href="../basics/fragments/index.html">
                <i class="fa fa-check"></i> <b>2.5.</b> 使用Fragment建立动态的UI
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.5.1" data-path="basics/fragments/creating.html">
            
            <a href="../basics/fragments/creating.html">
                <i class="fa fa-check"></i> <b>2.5.1.</b> 创建一个Fragment
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5.2" data-path="basics/fragments/fragment-ui.html">
            
            <a href="../basics/fragments/fragment-ui.html">
                <i class="fa fa-check"></i> <b>2.5.2.</b> 建立灵活动态的UI
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5.3" data-path="basics/fragments/communicating.html">
            
            <a href="../basics/fragments/communicating.html">
                <i class="fa fa-check"></i> <b>2.5.3.</b> Fragments之间的交互
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="basics/data-storage/index.html">
            
            <a href="../basics/data-storage/index.html">
                <i class="fa fa-check"></i> <b>2.6.</b> 数据保存
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.6.1" data-path="basics/data-storage/shared-preference.html">
            
            <a href="../basics/data-storage/shared-preference.html">
                <i class="fa fa-check"></i> <b>2.6.1.</b> 保存到Preference
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6.2" data-path="basics/data-storage/files.html">
            
            <a href="../basics/data-storage/files.html">
                <i class="fa fa-check"></i> <b>2.6.2.</b> 保存到文件
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6.3" data-path="basics/data-storage/database.html">
            
            <a href="../basics/data-storage/database.html">
                <i class="fa fa-check"></i> <b>2.6.3.</b> 保存到数据库
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="basics/intents/index.html">
            
            <a href="../basics/intents/index.html">
                <i class="fa fa-check"></i> <b>2.7.</b> 与其他应用的交互
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.7.1" data-path="basics/intents/sending.html">
            
            <a href="../basics/intents/sending.html">
                <i class="fa fa-check"></i> <b>2.7.1.</b> Intent的发送
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7.2" data-path="basics/intents/result.html">
            
            <a href="../basics/intents/result.html">
                <i class="fa fa-check"></i> <b>2.7.2.</b> 接收Activity返回的结果
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7.3" data-path="basics/intents/filters.html">
            
            <a href="../basics/intents/filters.html">
                <i class="fa fa-check"></i> <b>2.7.3.</b> Intent过滤
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="content-sharing/index.html">
            
            <a href="../content-sharing/index.html">
                <i class="fa fa-check"></i> <b>3.</b> 分享
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="content-sharing/sharing/index.html">
            
            <a href="../content-sharing/sharing/index.html">
                <i class="fa fa-check"></i> <b>3.1.</b> 分享简单的数据
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.1" data-path="content-sharing/sharing/send.html">
            
            <a href="../content-sharing/sharing/send.html">
                <i class="fa fa-check"></i> <b>3.1.1.</b> 给其他App发送简单的数据
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.1.2" data-path="content-sharing/sharing/receive.html">
            
            <a href="../content-sharing/sharing/receive.html">
                <i class="fa fa-check"></i> <b>3.1.2.</b> 接收从其他App返回的数据
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.1.3" data-path="content-sharing/sharing/shareaction.html">
            
            <a href="../content-sharing/sharing/shareaction.html">
                <i class="fa fa-check"></i> <b>3.1.3.</b> 添加一个简便的分享动作
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="content-sharing/secure-file-sharing/index.html">
            
            <a href="../content-sharing/secure-file-sharing/index.html">
                <i class="fa fa-check"></i> <b>3.2.</b> 分享文件
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.2.1" data-path="content-sharing/secure-file-sharing/setup-sharing.html">
            
            <a href="../content-sharing/secure-file-sharing/setup-sharing.html">
                <i class="fa fa-check"></i> <b>3.2.1.</b> 建立文件分享
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2.2" data-path="content-sharing/secure-file-sharing/sharing-file.html">
            
            <a href="../content-sharing/secure-file-sharing/sharing-file.html">
                <i class="fa fa-check"></i> <b>3.2.2.</b> 分享文件
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2.3" data-path="content-sharing/secure-file-sharing/request-file.html">
            
            <a href="../content-sharing/secure-file-sharing/request-file.html">
                <i class="fa fa-check"></i> <b>3.2.3.</b> 请求分享一个文件
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2.4" data-path="content-sharing/secure-file-sharing/retrieve-info.html">
            
            <a href="../content-sharing/secure-file-sharing/retrieve-info.html">
                <i class="fa fa-check"></i> <b>3.2.4.</b> 获取文件信息
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="content-sharing/beam-files/index.html">
            
            <a href="../content-sharing/beam-files/index.html">
                <i class="fa fa-check"></i> <b>3.3.</b> 使用NFC分享文件
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.3.1" data-path="content-sharing/beam-files/sending-files.html">
            
            <a href="../content-sharing/beam-files/sending-files.html">
                <i class="fa fa-check"></i> <b>3.3.1.</b> 发送文件给其他设备
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3.2" data-path="content-sharing/beam-files/receive-files.html">
            
            <a href="../content-sharing/beam-files/receive-files.html">
                <i class="fa fa-check"></i> <b>3.3.2.</b> 接收其他设备的文件
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="multimedia/index.html">
            
            <a href="../multimedia/index.html">
                <i class="fa fa-check"></i> <b>4.</b> 多媒体
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="multimedia/audio/index.html">
            
            <a href="../multimedia/audio/index.html">
                <i class="fa fa-check"></i> <b>4.1.</b> 管理音频播放
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.1" data-path="multimedia/audio/volume-playback.html">
            
            <a href="../multimedia/audio/volume-playback.html">
                <i class="fa fa-check"></i> <b>4.1.1.</b> 控制你得应用的音量与播放
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.1.2" data-path="multimedia/audio/audio-focus.html">
            
            <a href="../multimedia/audio/audio-focus.html">
                <i class="fa fa-check"></i> <b>4.1.2.</b> 管理音频焦点
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.1.3" data-path="multimedia/audio/audio-output.html">
            
            <a href="../multimedia/audio/audio-output.html">
                <i class="fa fa-check"></i> <b>4.1.3.</b> 兼容音频输出设备
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="multimedia/camera/index.html">
            
            <a href="../multimedia/camera/index.html">
                <i class="fa fa-check"></i> <b>4.2.</b> 拍照
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.2.1" data-path="multimedia/camera/photobasic.html">
            
            <a href="../multimedia/camera/photobasic.html">
                <i class="fa fa-check"></i> <b>4.2.1.</b> 简单的拍照
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2.2" data-path="multimedia/camera/videobasic.html">
            
            <a href="../multimedia/camera/videobasic.html">
                <i class="fa fa-check"></i> <b>4.2.2.</b> 简单的录像
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2.3" data-path="multimedia/camera/cameradirect.html">
            
            <a href="../multimedia/camera/cameradirect.html">
                <i class="fa fa-check"></i> <b>4.2.3.</b> 控制相机硬件
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="multimedia/printing/index.html">
            
            <a href="../multimedia/printing/index.html">
                <i class="fa fa-check"></i> <b>4.3.</b> 打印
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.3.1" data-path="multimedia/printing/photos.html">
            
            <a href="../multimedia/printing/photos.html">
                <i class="fa fa-check"></i> <b>4.3.1.</b> 打印照片
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3.2" data-path="multimedia/printing/html-docs.html">
            
            <a href="../multimedia/printing/html-docs.html">
                <i class="fa fa-check"></i> <b>4.3.2.</b> 打印HTML文档
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3.3" data-path="multimedia/printing/custom-docs.html">
            
            <a href="../multimedia/printing/custom-docs.html">
                <i class="fa fa-check"></i> <b>4.3.3.</b> 打印自定义文档
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="graphics/index.html">
            
            <a href="../graphics/index.html">
                <i class="fa fa-check"></i> <b>5.</b> 图像
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="graphics/displaying-bitmaps/index.html">
            
            <a href="../graphics/displaying-bitmaps/index.html">
                <i class="fa fa-check"></i> <b>5.1.</b> 高效显示Bitmap
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1.1" data-path="graphics/displaying-bitmaps/load-bitmap.html">
            
            <a href="../graphics/displaying-bitmaps/load-bitmap.html">
                <i class="fa fa-check"></i> <b>5.1.1.</b> 高效加载大图
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.1.2" data-path="graphics/displaying-bitmaps/process-bitmap.html">
            
            <a href="../graphics/displaying-bitmaps/process-bitmap.html">
                <i class="fa fa-check"></i> <b>5.1.2.</b> 非UI线程处理Bitmap
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.1.3" data-path="graphics/displaying-bitmaps/cache-bitmap.html">
            
            <a href="../graphics/displaying-bitmaps/cache-bitmap.html">
                <i class="fa fa-check"></i> <b>5.1.3.</b> 缓存Bitmap
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.1.4" data-path="graphics/displaying-bitmaps/manage-bitmap-memory.html">
            
            <a href="../graphics/displaying-bitmaps/manage-bitmap-memory.html">
                <i class="fa fa-check"></i> <b>5.1.4.</b> 管理Bitmap的内存占用
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.1.5" data-path="graphics/displaying-bitmaps/display-bitmap.html">
            
            <a href="../graphics/displaying-bitmaps/display-bitmap.html">
                <i class="fa fa-check"></i> <b>5.1.5.</b> 在UI上显示Bitmap
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="graphics/opengl/index.html">
            
            <a href="../graphics/opengl/index.html">
                <i class="fa fa-check"></i> <b>5.2.</b> 使用OpenGL ES显示图像
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.2.1" data-path="graphics/opengl/environment.html">
            
            <a href="../graphics/opengl/environment.html">
                <i class="fa fa-check"></i> <b>5.2.1.</b> 建立OpenGL ES的环境
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2.2" data-path="graphics/opengl/shapes.html">
            
            <a href="../graphics/opengl/shapes.html">
                <i class="fa fa-check"></i> <b>5.2.2.</b> 定义Shapes
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2.3" data-path="graphics/opengl/draw.html">
            
            <a href="../graphics/opengl/draw.html">
                <i class="fa fa-check"></i> <b>5.2.3.</b> 绘制Shapes
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2.4" data-path="graphics/opengl/projection.html">
            
            <a href="../graphics/opengl/projection.html">
                <i class="fa fa-check"></i> <b>5.2.4.</b> 运用投影与相机视图
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2.5" data-path="graphics/opengl/motion.html">
            
            <a href="../graphics/opengl/motion.html">
                <i class="fa fa-check"></i> <b>5.2.5.</b> 添加移动
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2.6" data-path="graphics/opengl/touch.html">
            
            <a href="../graphics/opengl/touch.html">
                <i class="fa fa-check"></i> <b>5.2.6.</b> 响应触摸事件
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="animations/index.html">
            
            <a href="../animations/index.html">
                <i class="fa fa-check"></i> <b>6.</b> 动画
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="animations/crossfade.html">
            
            <a href="../animations/crossfade.html">
                <i class="fa fa-check"></i> <b>6.1.</b> 淡入淡出两个View
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="animations/screen-slide.html">
            
            <a href="../animations/screen-slide.html">
                <i class="fa fa-check"></i> <b>6.2.</b> 使用ViewPager实现屏幕滑动
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="animations/cardflip.html">
            
            <a href="../animations/cardflip.html">
                <i class="fa fa-check"></i> <b>6.3.</b> 卡片翻转的动画
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="animations/zoom.html">
            
            <a href="../animations/zoom.html">
                <i class="fa fa-check"></i> <b>6.4.</b> 缩放动画
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="animations/layout.html">
            
            <a href="../animations/layout.html">
                <i class="fa fa-check"></i> <b>6.5.</b> 控件切换动画
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="connectivity/index.html">
            
            <a href="../connectivity/index.html">
                <i class="fa fa-check"></i> <b>7.</b> 连接
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1" data-path="connectivity/connect-devices-wireless/index.html">
            
            <a href="../connectivity/connect-devices-wireless/index.html">
                <i class="fa fa-check"></i> <b>7.1.</b> 无线连接设备
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1.1" data-path="connectivity/connect-devices-wireless/nsd.html">
            
            <a href="../connectivity/connect-devices-wireless/nsd.html">
                <i class="fa fa-check"></i> <b>7.1.1.</b> 使得网络服务可发现
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.1.2" data-path="connectivity/connect-devices-wireless/wifi-direct.html">
            
            <a href="../connectivity/connect-devices-wireless/wifi-direct.html">
                <i class="fa fa-check"></i> <b>7.1.2.</b> 使用WiFi建立P2P连接
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.1.3" data-path="connectivity/connect-devices-wireless/nsd-wifi-index.html">
            
            <a href="../connectivity/connect-devices-wireless/nsd-wifi-index.html">
                <i class="fa fa-check"></i> <b>7.1.3.</b> 使用WiFi P2P服务
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="connectivity/network-ops/index.html">
            
            <a href="../connectivity/network-ops/index.html">
                <i class="fa fa-check"></i> <b>7.2.</b> 网络连接操作
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.2.1" data-path="connectivity/network-ops/connecting.html">
            
            <a href="../connectivity/network-ops/connecting.html">
                <i class="fa fa-check"></i> <b>7.2.1.</b> 连接到网络
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.2.2" data-path="connectivity/network-ops/managing.html">
            
            <a href="../connectivity/network-ops/managing.html">
                <i class="fa fa-check"></i> <b>7.2.2.</b> 管理使用的网络
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.2.3" data-path="connectivity/network-ops/xml.html">
            
            <a href="../connectivity/network-ops/xml.html">
                <i class="fa fa-check"></i> <b>7.2.3.</b> 解析XML数据
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="connectivity/efficient-downloads/index.html">
            
            <a href="../connectivity/efficient-downloads/index.html">
                <i class="fa fa-check"></i> <b>7.3.</b> 高效下载
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.3.1" data-path="connectivity/efficient-downloads/efficient-network-access.html">
            
            <a href="../connectivity/efficient-downloads/efficient-network-access.html">
                <i class="fa fa-check"></i> <b>7.3.1.</b> 为网络访问更加高效而优化下载
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.3.2" data-path="connectivity/efficient-downloads/regular-update.html">
            
            <a href="../connectivity/efficient-downloads/regular-update.html">
                <i class="fa fa-check"></i> <b>7.3.2.</b> 最小化更新操作的影响
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.3.3" data-path="connectivity/efficient-downloads/redundant-redundant.html">
            
            <a href="../connectivity/efficient-downloads/redundant-redundant.html">
                <i class="fa fa-check"></i> <b>7.3.3.</b> 避免下载多余的数据
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.3.4" data-path="connectivity/efficient-downloads/connectivity-patterns.html">
            
            <a href="../connectivity/efficient-downloads/connectivity-patterns.html">
                <i class="fa fa-check"></i> <b>7.3.4.</b> 根据网络类型改变下载模式
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7.4" data-path="connectivity/sync-adapters/index.html">
            
            <a href="../connectivity/sync-adapters/index.html">
                <i class="fa fa-check"></i> <b>7.4.</b> 使用Sync Adapter传输数据
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.4.1" data-path="connectivity/sync-adapters/create-authenticator.html">
            
            <a href="../connectivity/sync-adapters/create-authenticator.html">
                <i class="fa fa-check"></i> <b>7.4.1.</b> 创建Stub授权器
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.4.2" data-path="connectivity/sync-adapters/create-stub-provider.html">
            
            <a href="../connectivity/sync-adapters/create-stub-provider.html">
                <i class="fa fa-check"></i> <b>7.4.2.</b> 创建Stub Content Provider
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.4.3" data-path="connectivity/sync-adapters/create-sync-adapter.html">
            
            <a href="../connectivity/sync-adapters/create-sync-adapter.html">
                <i class="fa fa-check"></i> <b>7.4.3.</b> 创建Sync Adpater
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.4.4" data-path="connectivity/sync-adapters/running-sync-adapter.html">
            
            <a href="../connectivity/sync-adapters/running-sync-adapter.html">
                <i class="fa fa-check"></i> <b>7.4.4.</b> 执行Sync Adpater
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7.5" data-path="connectivity/volley/index.html">
            
            <a href="../connectivity/volley/index.html">
                <i class="fa fa-check"></i> <b>7.5.</b> 使用Volley执行网络数据传输
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.5.1" data-path="connectivity/volley/simple.html">
            
            <a href="../connectivity/volley/simple.html">
                <i class="fa fa-check"></i> <b>7.5.1.</b> 发送简单的网络请求
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.5.2" data-path="connectivity/volley/request-queue.html">
            
            <a href="../connectivity/volley/request-queue.html">
                <i class="fa fa-check"></i> <b>7.5.2.</b> 建立请求队列
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.5.3" data-path="connectivity/volley/request.html">
            
            <a href="../connectivity/volley/request.html">
                <i class="fa fa-check"></i> <b>7.5.3.</b> 创建标准的网络请求
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.5.4" data-path="connectivity/volley/request-custom.html">
            
            <a href="../connectivity/volley/request-custom.html">
                <i class="fa fa-check"></i> <b>7.5.4.</b> 实现自定义的网络请求
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="8" data-path="cloud/index.html">
            
            <a href="../cloud/index.html">
                <i class="fa fa-check"></i> <b>8.</b> 云服务
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="8.1" data-path="cloud/cloudsync/index.html">
            
            <a href="../cloud/cloudsync/index.html">
                <i class="fa fa-check"></i> <b>8.1.</b> 云同步
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="8.1.1" data-path="cloud/cloudsync/backupapi.html">
            
            <a href="../cloud/cloudsync/backupapi.html">
                <i class="fa fa-check"></i> <b>8.1.1.</b> 使用备份API
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.1.2" data-path="cloud/cloudsync/gcm.html">
            
            <a href="../cloud/cloudsync/gcm.html">
                <i class="fa fa-check"></i> <b>8.1.2.</b> 使用Google Cloud Messaging
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="cloud/cloudsave/index.html">
            
            <a href="../cloud/cloudsave/index.html">
                <i class="fa fa-check"></i> <b>8.2.</b> 解决云同步的保存冲突
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="9" data-path="contacts-provider/index.html">
            
            <a href="../contacts-provider/index.html">
                <i class="fa fa-check"></i> <b>9.</b> 用户信息
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="9.1" data-path="contacts-provider/retrieve-names.html">
            
            <a href="../contacts-provider/retrieve-names.html">
                <i class="fa fa-check"></i> <b>9.1.</b> 获取联系人列表
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="contacts-provider/retrieve-detail.html">
            
            <a href="../contacts-provider/retrieve-detail.html">
                <i class="fa fa-check"></i> <b>9.2.</b> 获取联系人详情
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.3" data-path="contacts-provider/modify-data.html">
            
            <a href="../contacts-provider/modify-data.html">
                <i class="fa fa-check"></i> <b>9.3.</b> 修改联系人信息
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.4" data-path="contacts-provider/display-badge.html">
            
            <a href="../contacts-provider/display-badge.html">
                <i class="fa fa-check"></i> <b>9.4.</b> 显示联系人头像
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="10" data-path="location/index.html">
            
            <a href="../location/index.html">
                <i class="fa fa-check"></i> <b>10.</b> 位置信息
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="10.1" data-path="location/retrieve-current.html">
            
            <a href="../location/retrieve-current.html">
                <i class="fa fa-check"></i> <b>10.1.</b> 获取当前位置
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.2" data-path="location/retrieve-location-updates.html">
            
            <a href="../location/retrieve-location-updates.html">
                <i class="fa fa-check"></i> <b>10.2.</b> 获取位置更新
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.3" data-path="location/display-address.html">
            
            <a href="../location/display-address.html">
                <i class="fa fa-check"></i> <b>10.3.</b> 显示位置地址
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.4" data-path="location/geofencing.html">
            
            <a href="../location/geofencing.html">
                <i class="fa fa-check"></i> <b>10.4.</b> 创建并监视异常区域
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.5" data-path="location/activity-recognition.html">
            
            <a href="../location/activity-recognition.html">
                <i class="fa fa-check"></i> <b>10.5.</b> 识别用户的当下活动
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.6" data-path="location/location-testing.html">
            
            <a href="../location/location-testing.html">
                <i class="fa fa-check"></i> <b>10.6.</b> 使用模拟位置进行测试
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="11" data-path="wearables/index.html">
            
            <a href="../wearables/index.html">
                <i class="fa fa-check"></i> <b>11.</b> 为可穿戴设备创建应用
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="11.1" data-path="wearables/notifications/index.html">
            
            <a href="../wearables/notifications/index.html">
                <i class="fa fa-check"></i> <b>11.1.</b> 赋予Notification可穿戴特性
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="11.1.1" data-path="wearables/notifications/creating.html">
            
            <a href="../wearables/notifications/creating.html">
                <i class="fa fa-check"></i> <b>11.1.1.</b> 创建Notification
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="11.1.2" data-path="wearables/notifications/voice-input.html">
            
            <a href="../wearables/notifications/voice-input.html">
                <i class="fa fa-check"></i> <b>11.1.2.</b> 在Notifcation中接收语音输入
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="11.1.3" data-path="wearables/notifications/pages.html">
            
            <a href="../wearables/notifications/pages.html">
                <i class="fa fa-check"></i> <b>11.1.3.</b> 为Notification添加显示页面
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="11.1.4" data-path="wearables/notifications/stacks.html">
            
            <a href="../wearables/notifications/stacks.html">
                <i class="fa fa-check"></i> <b>11.1.4.</b> 以Stack的方式显示Notifications
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="11.2" data-path="wearables/apps/index.html">
            
            <a href="../wearables/apps/index.html">
                <i class="fa fa-check"></i> <b>11.2.</b> 创建可穿戴的应用
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="11.2.1" data-path="wearables/apps/creating.html">
            
            <a href="../wearables/apps/creating.html">
                <i class="fa fa-check"></i> <b>11.2.1.</b> 创建并执行可穿戴应用
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="11.2.2" data-path="wearables/apps/layouts.html">
            
            <a href="../wearables/apps/layouts.html">
                <i class="fa fa-check"></i> <b>11.2.2.</b> 创建自定义的布局
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="11.2.3" data-path="wearables/apps/voice.html">
            
            <a href="../wearables/apps/voice.html">
                <i class="fa fa-check"></i> <b>11.2.3.</b> 添加语音能力
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="11.2.4" data-path="wearables/apps/packaging.html">
            
            <a href="../wearables/apps/packaging.html">
                <i class="fa fa-check"></i> <b>11.2.4.</b> 打包可穿戴应用
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="11.2.5" data-path="wearables/apps/bt-debugging.html">
            
            <a href="../wearables/apps/bt-debugging.html">
                <i class="fa fa-check"></i> <b>11.2.5.</b> 通过蓝牙进行调试
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="11.3" data-path="wearables/data-layer/index.html">
            
            <a href="../wearables/data-layer/index.html">
                <i class="fa fa-check"></i> <b>11.3.</b> 发送并同步数据
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="11.3.1" data-path="wearables/data-layer/accessing.html">
            
            <a href="../wearables/data-layer/accessing.html">
                <i class="fa fa-check"></i> <b>11.3.1.</b> 访问可穿戴数据层
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="11.3.2" data-path="wearables/data-layer/data-items.html">
            
            <a href="../wearables/data-layer/data-items.html">
                <i class="fa fa-check"></i> <b>11.3.2.</b> 同步数据单元
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="11.3.3" data-path="wearables/data-layer/assets.html">
            
            <a href="../wearables/data-layer/assets.html">
                <i class="fa fa-check"></i> <b>11.3.3.</b> 传输资源
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="11.3.4" data-path="wearables/data-layer/messages.html">
            
            <a href="../wearables/data-layer/messages.html">
                <i class="fa fa-check"></i> <b>11.3.4.</b> 发送与接收消息
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="11.3.5" data-path="wearables/data-layer/events.html">
            
            <a href="../wearables/data-layer/events.html">
                <i class="fa fa-check"></i> <b>11.3.5.</b> 处理数据层的事件
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="12" data-path="ux/index.html">
            
            <a href="../ux/index.html">
                <i class="fa fa-check"></i> <b>12.</b> 交互
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="12.1" data-path="ux/design-nav/index.html">
            
            <a href="../ux/design-nav/index.html">
                <i class="fa fa-check"></i> <b>12.1.</b> 设计高效的导航
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="12.1.1" data-path="ux/design-nav/screen-planning.html">
            
            <a href="../ux/design-nav/screen-planning.html">
                <i class="fa fa-check"></i> <b>12.1.1.</b> 规划屏幕界面与他们之间的关系
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.1.2" data-path="ux/design-nav/multi-sizes.html">
            
            <a href="../ux/design-nav/multi-sizes.html">
                <i class="fa fa-check"></i> <b>12.1.2.</b> 为多种大小的屏幕进行规划
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.1.3" data-path="ux/design-nav/descendant-lateral.html">
            
            <a href="../ux/design-nav/descendant-lateral.html">
                <i class="fa fa-check"></i> <b>12.1.3.</b> 提供向下与侧滑的导航
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.1.4" data-path="ux/design-nav/ancestral-temporal.html">
            
            <a href="../ux/design-nav/ancestral-temporal.html">
                <i class="fa fa-check"></i> <b>12.1.4.</b> 提供向上与暂时的导航
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.1.5" data-path="ux/design-nav/wireframing.html">
            
            <a href="../ux/design-nav/wireframing.html">
                <i class="fa fa-check"></i> <b>12.1.5.</b> 综合上面所有的导航
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="12.2" data-path="ux/implement-nav/index.html">
            
            <a href="../ux/implement-nav/index.html">
                <i class="fa fa-check"></i> <b>12.2.</b> 实现高效的导航
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="12.2.1" data-path="ux/implement-nav/lateral.html">
            
            <a href="../ux/implement-nav/lateral.html">
                <i class="fa fa-check"></i> <b>12.2.1.</b> 使用Tabs创建Swipe视图
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.2.2" data-path="ux/implement-nav/nav-drawer.html">
            
            <a href="../ux/implement-nav/nav-drawer.html">
                <i class="fa fa-check"></i> <b>12.2.2.</b> 创建抽屉导航
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.2.3" data-path="ux/implement-nav/ancestral.html">
            
            <a href="../ux/implement-nav/ancestral.html">
                <i class="fa fa-check"></i> <b>12.2.3.</b> 提供向上的导航
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.2.4" data-path="ux/implement-nav/temporal.html">
            
            <a href="../ux/implement-nav/temporal.html">
                <i class="fa fa-check"></i> <b>12.2.4.</b> 提供向后的导航
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.2.5" data-path="ux/implement-nav/descendant.html">
            
            <a href="../ux/implement-nav/descendant.html">
                <i class="fa fa-check"></i> <b>12.2.5.</b> 实现向下的导航
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="12.3" data-path="ux/notify-user/index.html">
            
            <a href="../ux/notify-user/index.html">
                <i class="fa fa-check"></i> <b>12.3.</b> 通知提示用户
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="12.3.1" data-path="ux/notify-user/build-notification.html">
            
            <a href="../ux/notify-user/build-notification.html">
                <i class="fa fa-check"></i> <b>12.3.1.</b> 建立Notification
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.3.2" data-path="ux/notify-user/nav.html">
            
            <a href="../ux/notify-user/nav.html">
                <i class="fa fa-check"></i> <b>12.3.2.</b> 当启动Activity时保留导航
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.3.3" data-path="ux/notify-user/update-notification.html">
            
            <a href="../ux/notify-user/update-notification.html">
                <i class="fa fa-check"></i> <b>12.3.3.</b> 更新Notification
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.3.4" data-path="ux/notify-user/expand-notification.html">
            
            <a href="../ux/notify-user/expand-notification.html">
                <i class="fa fa-check"></i> <b>12.3.4.</b> 使用BigView风格
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.3.5" data-path="ux/notify-user/progess-notification.html">
            
            <a href="../ux/notify-user/progess-notification.html">
                <i class="fa fa-check"></i> <b>12.3.5.</b> 显示Notification进度
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="12.4" data-path="ux/search/index.html">
            
            <a href="../ux/search/index.html">
                <i class="fa fa-check"></i> <b>12.4.</b> 增加搜索功能
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="12.4.1" data-path="ux/search/setup.html">
            
            <a href="../ux/search/setup.html">
                <i class="fa fa-check"></i> <b>12.4.1.</b> 建立搜索界面
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.4.2" data-path="ux/search/search.html">
            
            <a href="../ux/search/search.html">
                <i class="fa fa-check"></i> <b>12.4.2.</b> 保存并搜索数据
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.4.3" data-path="ux/search/back-compat.html">
            
            <a href="../ux/search/back-compat.html">
                <i class="fa fa-check"></i> <b>12.4.3.</b> 保持向下兼容
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="12.5" data-path="ux/app-indexing/index.html">
            
            <a href="../ux/app-indexing/index.html">
                <i class="fa fa-check"></i> <b>12.5.</b> 使得你的App内容可被Google搜索
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="12.5.1" data-path="ux/app-indexing/deep-linking.html">
            
            <a href="../ux/app-indexing/deep-linking.html">
                <i class="fa fa-check"></i> <b>12.5.1.</b> 为App内容开启深度链接
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.5.2" data-path="ux/app-indexing/enable-app-indexing.html">
            
            <a href="../ux/app-indexing/enable-app-indexing.html">
                <i class="fa fa-check"></i> <b>12.5.2.</b> 为索引指定App内容
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="13" data-path="ui/index.html">
            
            <a href="../ui/index.html">
                <i class="fa fa-check"></i> <b>13.</b> UI
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="13.1" data-path="ui/multiscreen/index.html">
            
            <a href="../ui/multiscreen/index.html">
                <i class="fa fa-check"></i> <b>13.1.</b> 为多屏幕设计
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="13.1.1" data-path="ui/multiscreen/screen-sizes.html">
            
            <a href="../ui/multiscreen/screen-sizes.html">
                <i class="fa fa-check"></i> <b>13.1.1.</b> 兼容不同的屏幕大小
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="13.1.2" data-path="ui/multiscreen/screen-desities.html">
            
            <a href="../ui/multiscreen/screen-desities.html">
                <i class="fa fa-check"></i> <b>13.1.2.</b> 兼容不同的屏幕密度
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="13.1.3" data-path="ui/multiscreen/adapt-ui.html">
            
            <a href="../ui/multiscreen/adapt-ui.html">
                <i class="fa fa-check"></i> <b>13.1.3.</b> 实现可适应的UI
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="13.2" data-path="ui/tv/index.html">
            
            <a href="../ui/tv/index.html">
                <i class="fa fa-check"></i> <b>13.2.</b> 为TV进行设计
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="13.2.1" data-path="ui/tv/optimize-layouts-tv.html">
            
            <a href="../ui/tv/optimize-layouts-tv.html">
                <i class="fa fa-check"></i> <b>13.2.1.</b> 为TV优化Layout
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="13.2.2" data-path="ui/tv/optimize-nav-tv.html">
            
            <a href="../ui/tv/optimize-nav-tv.html">
                <i class="fa fa-check"></i> <b>13.2.2.</b> 为TV优化导航
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="13.2.3" data-path="ui/tv/unsupport-features-tv.html">
            
            <a href="../ui/tv/unsupport-features-tv.html">
                <i class="fa fa-check"></i> <b>13.2.3.</b> 处理不支持TV的功能
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="13.3" data-path="ui/custom-view/index.html">
            
            <a href="../ui/custom-view/index.html">
                <i class="fa fa-check"></i> <b>13.3.</b> 创建自定义View
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="13.3.1" data-path="ui/custom-view/create-view.html">
            
            <a href="../ui/custom-view/create-view.html">
                <i class="fa fa-check"></i> <b>13.3.1.</b> 创建自定义的View类
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="13.3.2" data-path="ui/custom-view/custom-draw.html">
            
            <a href="../ui/custom-view/custom-draw.html">
                <i class="fa fa-check"></i> <b>13.3.2.</b> 实现自定义View的绘制
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="13.3.3" data-path="ui/custom-view/make-interactive.html">
            
            <a href="../ui/custom-view/make-interactive.html">
                <i class="fa fa-check"></i> <b>13.3.3.</b> 使得View可交互
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="13.3.4" data-path="ui/custom-view/optimize-view.html">
            
            <a href="../ui/custom-view/optimize-view.html">
                <i class="fa fa-check"></i> <b>13.3.4.</b> 优化自定义View
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="13.4" data-path="ui/backward-compatible-ui/index.html">
            
            <a href="../ui/backward-compatible-ui/index.html">
                <i class="fa fa-check"></i> <b>13.4.</b> 创建向后兼容的UI
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="13.4.1" data-path="ui/backward-compatible-ui/abstract.html">
            
            <a href="../ui/backward-compatible-ui/abstract.html">
                <i class="fa fa-check"></i> <b>13.4.1.</b> 抽象新的APIs
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="13.4.2" data-path="ui/backward-compatible-ui/new-impl.html">
            
            <a href="../ui/backward-compatible-ui/new-impl.html">
                <i class="fa fa-check"></i> <b>13.4.2.</b> 代理至新的APIs
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="13.4.3" data-path="ui/backward-compatible-ui/older-impl.html">
            
            <a href="../ui/backward-compatible-ui/older-impl.html">
                <i class="fa fa-check"></i> <b>13.4.3.</b> 使用旧的APIs实现新API的效果
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="13.4.4" data-path="ui/backward-compatible-ui/using-component.html">
            
            <a href="../ui/backward-compatible-ui/using-component.html">
                <i class="fa fa-check"></i> <b>13.4.4.</b> 使用版本敏感的组件
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="13.5" data-path="ui/accessibility/index.html">
            
            <a href="../ui/accessibility/index.html">
                <i class="fa fa-check"></i> <b>13.5.</b> 实现辅助功能
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="13.5.1" data-path="ui/accessibility/accessible-app.html">
            
            <a href="../ui/accessibility/accessible-app.html">
                <i class="fa fa-check"></i> <b>13.5.1.</b> 开发辅助程序
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="13.5.2" data-path="ui/accessibility/accessible-service.html">
            
            <a href="../ui/accessibility/accessible-service.html">
                <i class="fa fa-check"></i> <b>13.5.2.</b> 开发辅助服务
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="13.6" data-path="ui/system-ui/index.html">
            
            <a href="../ui/system-ui/index.html">
                <i class="fa fa-check"></i> <b>13.6.</b> 管理系统UI
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="13.6.1" data-path="ui/system-ui/dim.html">
            
            <a href="../ui/system-ui/dim.html">
                <i class="fa fa-check"></i> <b>13.6.1.</b> 淡化系统Bar
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="13.6.2" data-path="ui/system-ui/hide-ui.html">
            
            <a href="../ui/system-ui/hide-ui.html">
                <i class="fa fa-check"></i> <b>13.6.2.</b> 隐藏系统Bar
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="13.6.3" data-path="ui/system-ui/hide-nav.html">
            
            <a href="../ui/system-ui/hide-nav.html">
                <i class="fa fa-check"></i> <b>13.6.3.</b> 隐藏导航Bar
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="13.6.4" data-path="ui/system-ui/immersive.html">
            
            <a href="../ui/system-ui/immersive.html">
                <i class="fa fa-check"></i> <b>13.6.4.</b> 全屏沉浸式应用
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="13.6.5" data-path="ui/system-ui/visibility.html">
            
            <a href="../ui/system-ui/visibility.html">
                <i class="fa fa-check"></i> <b>13.6.5.</b> 响应UI可见性的变化
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="14" data-path="input/index.html">
            
            <a href="../input/index.html">
                <i class="fa fa-check"></i> <b>14.</b> 用户输入
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="14.1" data-path="input/gestures/index.html">
            
            <a href="../input/gestures/index.html">
                <i class="fa fa-check"></i> <b>14.1.</b> 使用触摸手势
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="14.1.1" data-path="input/gestures/detector.html">
            
            <a href="../input/gestures/detector.html">
                <i class="fa fa-check"></i> <b>14.1.1.</b> 检测常用的手势
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="14.1.2" data-path="input/gestures/movement.html">
            
            <a href="../input/gestures/movement.html">
                <i class="fa fa-check"></i> <b>14.1.2.</b> 跟踪手势移动
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="14.1.3" data-path="input/gestures/scroll.html">
            
            <a href="../input/gestures/scroll.html">
                <i class="fa fa-check"></i> <b>14.1.3.</b> Scroll手势动画
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="14.1.4" data-path="input/gestures/multi.html">
            
            <a href="../input/gestures/multi.html">
                <i class="fa fa-check"></i> <b>14.1.4.</b> 处理多触摸手势
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="14.1.5" data-path="input/gestures/scale.html">
            
            <a href="../input/gestures/scale.html">
                <i class="fa fa-check"></i> <b>14.1.5.</b> 拖拽与缩放
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="14.1.6" data-path="input/gestures/viewgroup.html">
            
            <a href="../input/gestures/viewgroup.html">
                <i class="fa fa-check"></i> <b>14.1.6.</b> 管理ViewGroup中的触摸事件
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="14.2" data-path="input/keyboard-input/index.html">
            
            <a href="../input/keyboard-input/index.html">
                <i class="fa fa-check"></i> <b>14.2.</b> 处理键盘输入
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="14.2.1" data-path="input/keyboard-input/type.html">
            
            <a href="../input/keyboard-input/type.html">
                <i class="fa fa-check"></i> <b>14.2.1.</b> 指定输入法类型
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="14.2.2" data-path="input/keyboard-input/visibility.html">
            
            <a href="../input/keyboard-input/visibility.html">
                <i class="fa fa-check"></i> <b>14.2.2.</b> 处理输入法可见性
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="14.2.3" data-path="input/keyboard-input/navigation.html">
            
            <a href="../input/keyboard-input/navigation.html">
                <i class="fa fa-check"></i> <b>14.2.3.</b> 兼容硬件导航
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="14.2.4" data-path="input/keyboard-input/commands.html">
            
            <a href="../input/keyboard-input/commands.html">
                <i class="fa fa-check"></i> <b>14.2.4.</b> 处理按键动作
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="14.3" data-path="input/game-controller/index.html">
            
            <a href="../input/game-controller/index.html">
                <i class="fa fa-check"></i> <b>14.3.</b> 兼容游戏控制器
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="14.3.1" data-path="input/game-controller/controller-inputs.html">
            
            <a href="../input/game-controller/controller-inputs.html">
                <i class="fa fa-check"></i> <b>14.3.1.</b> 处理控制器输入动作
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="14.3.2" data-path="input/game-controller/compatibility.html">
            
            <a href="../input/game-controller/compatibility.html">
                <i class="fa fa-check"></i> <b>14.3.2.</b> 支持不同的Android系统版本
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="14.3.3" data-path="input/game-controller/multi-controller.html">
            
            <a href="../input/game-controller/multi-controller.html">
                <i class="fa fa-check"></i> <b>14.3.3.</b> 支持多个控制器
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="15" data-path="background-jobs/index.html">
            
            <a href="../background-jobs/index.html">
                <i class="fa fa-check"></i> <b>15.</b> 后台任务
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="15.1" data-path="background-jobs/run-background-service/index.html">
            
            <a href="../background-jobs/run-background-service/index.html">
                <i class="fa fa-check"></i> <b>15.1.</b> 在IntentService中执行后台任务
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="15.1.1" data-path="background-jobs/run-background-service/create-service.html">
            
            <a href="../background-jobs/run-background-service/create-service.html">
                <i class="fa fa-check"></i> <b>15.1.1.</b> 创建IntentService
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="15.1.2" data-path="background-jobs/run-background-service/send-request.html">
            
            <a href="../background-jobs/run-background-service/send-request.html">
                <i class="fa fa-check"></i> <b>15.1.2.</b> 发送工作任务到IntentService
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="15.1.3" data-path="background-jobs/run-background-service/report-status.html">
            
            <a href="../background-jobs/run-background-service/report-status.html">
                <i class="fa fa-check"></i> <b>15.1.3.</b> 报告后台任务执行状态
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="15.2" data-path="background-jobs/load-data-background/index.html">
            
            <a href="../background-jobs/load-data-background/index.html">
                <i class="fa fa-check"></i> <b>15.2.</b> 使用CursorLoader在后台加载数据
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="15.2.1" data-path="background-jobs/load-data-background/setup-loader.html">
            
            <a href="../background-jobs/load-data-background/setup-loader.html">
                <i class="fa fa-check"></i> <b>15.2.1.</b> 使用CursorLoader执行查询任务
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="15.2.2" data-path="background-jobs/load-data-background/handle-result.html">
            
            <a href="../background-jobs/load-data-background/handle-result.html">
                <i class="fa fa-check"></i> <b>15.2.2.</b> 处理查询的结果
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="15.3" data-path="background-jobs/scheduling/index.html">
            
            <a href="../background-jobs/scheduling/index.html">
                <i class="fa fa-check"></i> <b>15.3.</b> 管理设备的唤醒状态
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="15.3.1" data-path="background-jobs/scheduling/wake-lock.html">
            
            <a href="../background-jobs/scheduling/wake-lock.html">
                <i class="fa fa-check"></i> <b>15.3.1.</b> 保持设备的唤醒
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="15.3.2" data-path="background-jobs/scheduling/alarms.html">
            
            <a href="../background-jobs/scheduling/alarms.html">
                <i class="fa fa-check"></i> <b>15.3.2.</b> 制定重复定时的任务
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="16" data-path="performance/index.html">
            
            <a href="../performance/index.html">
                <i class="fa fa-check"></i> <b>16.</b> 性能优化
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="16.1" data-path="performance/memory.html">
            
            <a href="../performance/memory.html">
                <i class="fa fa-check"></i> <b>16.1.</b> 管理应用的内存
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="16.2" data-path="performance/performance-tips.html">
            
            <a href="../performance/performance-tips.html">
                <i class="fa fa-check"></i> <b>16.2.</b> 性能优化Tips
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="16.3" data-path="performance/improving-layouts/index.html">
            
            <a href="../performance/improving-layouts/index.html">
                <i class="fa fa-check"></i> <b>16.3.</b> 提升Layout的性能
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="16.3.1" data-path="performance/improving-layouts/optimizing-layout.html">
            
            <a href="../performance/improving-layouts/optimizing-layout.html">
                <i class="fa fa-check"></i> <b>16.3.1.</b> 优化layout的层级
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="16.3.2" data-path="performance/improving-layouts/reuse-layouts.html">
            
            <a href="../performance/improving-layouts/reuse-layouts.html">
                <i class="fa fa-check"></i> <b>16.3.2.</b> 使用include标签重用layouts
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="16.3.3" data-path="performance/improving-layouts/loading-ondemand.html">
            
            <a href="../performance/improving-layouts/loading-ondemand.html">
                <i class="fa fa-check"></i> <b>16.3.3.</b> 按需加载视图
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="16.3.4" data-path="performance/improving-layouts/smooth-scrolling.html">
            
            <a href="../performance/improving-layouts/smooth-scrolling.html">
                <i class="fa fa-check"></i> <b>16.3.4.</b> 使得ListView滑动顺畅
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="16.4" data-path="performance/monitor-device-state/index.html">
            
            <a href="../performance/monitor-device-state/index.html">
                <i class="fa fa-check"></i> <b>16.4.</b> 优化电池寿命
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="16.4.1" data-path="performance/monitor-device-state/battery-monitor.html">
            
            <a href="../performance/monitor-device-state/battery-monitor.html">
                <i class="fa fa-check"></i> <b>16.4.1.</b> 监测电量与充电状态
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="16.4.2" data-path="performance/monitor-device-state/docking-monitor.html">
            
            <a href="../performance/monitor-device-state/docking-monitor.html">
                <i class="fa fa-check"></i> <b>16.4.2.</b> 判断与监测Docking状态
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="16.4.3" data-path="performance/monitor-device-state/connectivity-monitor.html">
            
            <a href="../performance/monitor-device-state/connectivity-monitor.html">
                <i class="fa fa-check"></i> <b>16.4.3.</b> 判断与监测网络连接状态
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="16.4.4" data-path="performance/monitor-device-state/manifest-receivers.html">
            
            <a href="../performance/monitor-device-state/manifest-receivers.html">
                <i class="fa fa-check"></i> <b>16.4.4.</b> 根据需要操作Broadcast接受者
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="16.5" data-path="performance/multi-threads/index.html">
            
            <a href="../performance/multi-threads/index.html">
                <i class="fa fa-check"></i> <b>16.5.</b> 多线程操作
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="16.5.1" data-path="performance/multi-threads/define-runnable.html">
            
            <a href="../performance/multi-threads/define-runnable.html">
                <i class="fa fa-check"></i> <b>16.5.1.</b> 在一个线程中执行一段特定的代码
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="16.5.2" data-path="performance/multi-threads/create-threadpool.html">
            
            <a href="../performance/multi-threads/create-threadpool.html">
                <i class="fa fa-check"></i> <b>16.5.2.</b> 为多线程创建线程池
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="16.5.3" data-path="performance/multi-threads/run-code.html">
            
            <a href="../performance/multi-threads/run-code.html">
                <i class="fa fa-check"></i> <b>16.5.3.</b> 在线程池中的一个线程里执行代码
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="16.5.4" data-path="performance/multi-threads/communicate-ui.html">
            
            <a href="../performance/multi-threads/communicate-ui.html">
                <i class="fa fa-check"></i> <b>16.5.4.</b> 与UI线程通信
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="16.6" data-path="performance/perf-anr/index.html">
            
            <a href="../performance/perf-anr/index.html">
                <i class="fa fa-check"></i> <b>16.6.</b> 避免ANR
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="16.7" data-path="performance/perf-anr/index.html">
            
            <a href="../performance/perf-anr/index.html">
                <i class="fa fa-check"></i> <b>16.7.</b> 避免出现程序无响应ANR
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="16.8" data-path="performance/perf-jni/index.html">
            
            <a href="../performance/perf-jni/index.html">
                <i class="fa fa-check"></i> <b>16.8.</b> JNI Tips
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="16.9" data-path="performance/smp/index.html">
            
            <a href="../performance/smp/index.html">
                <i class="fa fa-check"></i> <b>16.9.</b> SMP for Android
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="17" data-path="security/index.html">
            
            <a href="../security/index.html">
                <i class="fa fa-check"></i> <b>17.</b> 安全与隐私
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="17.1" data-path="security/security-tips.html">
            
            <a href="../security/security-tips.html">
                <i class="fa fa-check"></i> <b>17.1.</b> Security Tips
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="17.2" data-path="security/security-ssl.html">
            
            <a href="../security/security-ssl.html">
                <i class="fa fa-check"></i> <b>17.2.</b> 使用HTTPS与SSL
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="17.3" data-path="security/enterprise.html">
            
            <a href="../security/enterprise.html">
                <i class="fa fa-check"></i> <b>17.3.</b> 企业版App
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="18" data-path="testing/index.html">
            
            <a href="../testing/index.html">
                <i class="fa fa-check"></i> <b>18.</b> 测试程序
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="18.1" data-path="testing/activity-testing/index.html">
            
            <a href="../testing/activity-testing/index.html">
                <i class="fa fa-check"></i> <b>18.1.</b> 测试你的Activity
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="18.1.1" data-path="testing/activity-testing/prepare-activity-testing.html">
            
            <a href="../testing/activity-testing/prepare-activity-testing.html">
                <i class="fa fa-check"></i> <b>18.1.1.</b> 建立测试环境
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="18.1.2" data-path="testing/activity-testing/activity-basic-testing.html">
            
            <a href="../testing/activity-testing/activity-basic-testing.html">
                <i class="fa fa-check"></i> <b>18.1.2.</b> 创建与执行测试用例
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="18.1.3" data-path="testing/activity-testing/activity-ui-testing.html">
            
            <a href="../testing/activity-testing/activity-ui-testing.html">
                <i class="fa fa-check"></i> <b>18.1.3.</b> 测试UI组件
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="18.1.4" data-path="testing/activity-testing/activity-unit-testing.html">
            
            <a href="../testing/activity-testing/activity-unit-testing.html">
                <i class="fa fa-check"></i> <b>18.1.4.</b> 创建单元测试
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="18.1.5" data-path="testing/activity-testing/activity-function-testing.html">
            
            <a href="../testing/activity-testing/activity-function-testing.html">
                <i class="fa fa-check"></i> <b>18.1.5.</b> 创建功能测试
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="19" data-path="distribute/index.html">
            
            <a href="../distribute/index.html">
                <i class="fa fa-check"></i> <b>19.</b> 分发与盈利
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="19.1" data-path="distribute/in-app-billing/index.html">
            
            <a href="../distribute/in-app-billing/index.html">
                <i class="fa fa-check"></i> <b>19.1.</b> 售卖App内置产品
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="19.1.1" data-path="distribute/in-app-billing/prepare-iab-app.html">
            
            <a href="../distribute/in-app-billing/prepare-iab-app.html">
                <i class="fa fa-check"></i> <b>19.1.1.</b> 准备你的App
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="19.1.2" data-path="distribute/in-app-billing/list-iab-products.html">
            
            <a href="../distribute/in-app-billing/list-iab-products.html">
                <i class="fa fa-check"></i> <b>19.1.2.</b> 建立售卖的产品
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="19.1.3" data-path="distribute/in-app-billing/purchase-iab-products.html">
            
            <a href="../distribute/in-app-billing/purchase-iab-products.html">
                <i class="fa fa-check"></i> <b>19.1.3.</b> 购买产品
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="19.1.4" data-path="distribute/in-app-billing/test-iab-app.html">
            
            <a href="../distribute/in-app-billing/test-iab-app.html">
                <i class="fa fa-check"></i> <b>19.1.4.</b> 测试你的App
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="19.2" data-path="distribute/multi-apks/index.html">
            
            <a href="../distribute/multi-apks/index.html">
                <i class="fa fa-check"></i> <b>19.2.</b> 维护多个APK
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="19.2.1" data-path="distribute/multi-apks/api.html">
            
            <a href="../distribute/multi-apks/api.html">
                <i class="fa fa-check"></i> <b>19.2.1.</b> 为不同API Level创建多个APK
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="19.2.2" data-path="distribute/multi-apks/screen-size.html">
            
            <a href="../distribute/multi-apks/screen-size.html">
                <i class="fa fa-check"></i> <b>19.2.2.</b> 为不同屏幕大小创建多个APK
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="19.2.3" data-path="distribute/multi-apks/texture.html">
            
            <a href="../distribute/multi-apks/texture.html">
                <i class="fa fa-check"></i> <b>19.2.3.</b> 为不同的GL Texture创建多个APK
            </a>
            
            
        </li>
    
        <li class="chapter " data-level="19.2.4" data-path="distribute/multi-apks/multiple.html">
            
            <a href="../distribute/multi-apks/multiple.html">
                <i class="fa fa-check"></i> <b>19.2.4.</b> 为2种以上的维度创建多个APK
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="19.3" data-path="distribute/monetization/index.html">
            
            <a href="../distribute/monetization/index.html">
                <i class="fa fa-check"></i> <b>19.3.</b> App盈利
            </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="19.3.1" data-path="distribute/monetization/ads-and-ux.html">
            
            <a href="../distribute/monetization/ads-and-ux.html">
                <i class="fa fa-check"></i> <b>19.3.1.</b> 在不影响用户体验的前提下添加广告
            </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    


        
        <li class="divider"></li>
        <li>
            <a href="http://www.gitbook.io/" target="blank" class="gitbook-link">Generated using GitBook</a>
        </li>
        
    </ul>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="page-wrapper" tabindex="-1">
                <div class="book-progress">
    <div class="bar">
        <div class="inner" style="width: 44.31818181818182%;min-width: 43.93939393939394%;"></div>
    </div>
    <div class="chapters">
    
        <a href="../index.html" title="序言" class="chapter done new-chapter" data-progress="1" style="left: 0%;"></a>
    
        <a href="../basics/index.html" title="从这里开始" class="chapter done new-chapter" data-progress="2" style="left: 0.3787878787878788%;"></a>
    
        <a href="../basics/firstapp/index.html" title="建立你的第一个App" class="chapter done " data-progress="2.1" style="left: 0.7575757575757576%;"></a>
    
        <a href="../basics/firstapp/creating-project.html" title="创建一个Android项目" class="chapter done " data-progress="2.1.1" style="left: 1.1363636363636365%;"></a>
    
        <a href="../basics/firstapp/running-app.html" title="执行你的程序" class="chapter done " data-progress="2.1.2" style="left: 1.5151515151515151%;"></a>
    
        <a href="../basics/firstapp/building-ui.html" title="建立一个简单的用户界面" class="chapter done " data-progress="2.1.3" style="left: 1.893939393939394%;"></a>
    
        <a href="../basics/firstapp/starting-activity.html" title="启动另外的Activity" class="chapter done " data-progress="2.1.4" style="left: 2.272727272727273%;"></a>
    
        <a href="../basics/actionbar/index.html" title="添加ActionBar" class="chapter done " data-progress="2.2" style="left: 2.6515151515151514%;"></a>
    
        <a href="../basics/actionbar/setting-up.html" title="建立ActionBar" class="chapter done " data-progress="2.2.1" style="left: 3.0303030303030303%;"></a>
    
        <a href="../basics/actionbar/adding-buttons.html" title="添加Action按钮" class="chapter done " data-progress="2.2.2" style="left: 3.409090909090909%;"></a>
    
        <a href="../basics/actionbar/styling.html" title="ActionBar的风格化" class="chapter done " data-progress="2.2.3" style="left: 3.787878787878788%;"></a>
    
        <a href="../basics/actionbar/overlaying.html" title="ActionBar的覆盖层叠" class="chapter done " data-progress="2.2.4" style="left: 4.166666666666667%;"></a>
    
        <a href="../basics/supporting-devices/index.html" title="兼容不同的设备" class="chapter done " data-progress="2.3" style="left: 4.545454545454546%;"></a>
    
        <a href="../basics/supporting-devices/languages.html" title="适配不同的语言" class="chapter done " data-progress="2.3.1" style="left: 4.924242424242424%;"></a>
    
        <a href="../basics/supporting-devices/screens.html" title="适配不同的屏幕" class="chapter done " data-progress="2.3.2" style="left: 5.303030303030303%;"></a>
    
        <a href="../basics/supporting-devices/platforms.html" title="适配不同的系统版本" class="chapter done " data-progress="2.3.3" style="left: 5.681818181818182%;"></a>
    
        <a href="../basics/activity-lifecycle/index.html" title="管理Activity的生命周期" class="chapter done " data-progress="2.4" style="left: 6.0606060606060606%;"></a>
    
        <a href="../basics/activity-lifecycle/starting.html" title="启动与销毁Activity" class="chapter done " data-progress="2.4.1" style="left: 6.4393939393939394%;"></a>
    
        <a href="../basics/activity-lifecycle/pausing.html" title="暂停与恢复Activity" class="chapter done " data-progress="2.4.2" style="left: 6.818181818181818%;"></a>
    
        <a href="../basics/activity-lifecycle/stopping.html" title="停止与重启Activity" class="chapter done " data-progress="2.4.3" style="left: 7.196969696969697%;"></a>
    
        <a href="../basics/activity-lifecycle/recreating.html" title="重新创建Activity" class="chapter done " data-progress="2.4.4" style="left: 7.575757575757576%;"></a>
    
        <a href="../basics/fragments/index.html" title="使用Fragment建立动态的UI" class="chapter done " data-progress="2.5" style="left: 7.954545454545454%;"></a>
    
        <a href="../basics/fragments/creating.html" title="创建一个Fragment" class="chapter done " data-progress="2.5.1" style="left: 8.333333333333334%;"></a>
    
        <a href="../basics/fragments/fragment-ui.html" title="建立灵活动态的UI" class="chapter done " data-progress="2.5.2" style="left: 8.712121212121213%;"></a>
    
        <a href="../basics/fragments/communicating.html" title="Fragments之间的交互" class="chapter done " data-progress="2.5.3" style="left: 9.090909090909092%;"></a>
    
        <a href="../basics/data-storage/index.html" title="数据保存" class="chapter done " data-progress="2.6" style="left: 9.469696969696969%;"></a>
    
        <a href="../basics/data-storage/shared-preference.html" title="保存到Preference" class="chapter done " data-progress="2.6.1" style="left: 9.848484848484848%;"></a>
    
        <a href="../basics/data-storage/files.html" title="保存到文件" class="chapter done " data-progress="2.6.2" style="left: 10.227272727272727%;"></a>
    
        <a href="../basics/data-storage/database.html" title="保存到数据库" class="chapter done " data-progress="2.6.3" style="left: 10.606060606060606%;"></a>
    
        <a href="../basics/intents/index.html" title="与其他应用的交互" class="chapter done " data-progress="2.7" style="left: 10.984848484848484%;"></a>
    
        <a href="../basics/intents/sending.html" title="Intent的发送" class="chapter done " data-progress="2.7.1" style="left: 11.363636363636363%;"></a>
    
        <a href="../basics/intents/result.html" title="接收Activity返回的结果" class="chapter done " data-progress="2.7.2" style="left: 11.742424242424242%;"></a>
    
        <a href="../basics/intents/filters.html" title="Intent过滤" class="chapter done " data-progress="2.7.3" style="left: 12.121212121212121%;"></a>
    
        <a href="../content-sharing/index.html" title="分享" class="chapter done new-chapter" data-progress="3" style="left: 12.5%;"></a>
    
        <a href="../content-sharing/sharing/index.html" title="分享简单的数据" class="chapter done " data-progress="3.1" style="left: 12.878787878787879%;"></a>
    
        <a href="../content-sharing/sharing/send.html" title="给其他App发送简单的数据" class="chapter done " data-progress="3.1.1" style="left: 13.257575757575758%;"></a>
    
        <a href="../content-sharing/sharing/receive.html" title="接收从其他App返回的数据" class="chapter done " data-progress="3.1.2" style="left: 13.636363636363637%;"></a>
    
        <a href="../content-sharing/sharing/shareaction.html" title="添加一个简便的分享动作" class="chapter done " data-progress="3.1.3" style="left: 14.015151515151516%;"></a>
    
        <a href="../content-sharing/secure-file-sharing/index.html" title="分享文件" class="chapter done " data-progress="3.2" style="left: 14.393939393939394%;"></a>
    
        <a href="../content-sharing/secure-file-sharing/setup-sharing.html" title="建立文件分享" class="chapter done " data-progress="3.2.1" style="left: 14.772727272727273%;"></a>
    
        <a href="../content-sharing/secure-file-sharing/sharing-file.html" title="分享文件" class="chapter done " data-progress="3.2.2" style="left: 15.151515151515152%;"></a>
    
        <a href="../content-sharing/secure-file-sharing/request-file.html" title="请求分享一个文件" class="chapter done " data-progress="3.2.3" style="left: 15.530303030303031%;"></a>
    
        <a href="../content-sharing/secure-file-sharing/retrieve-info.html" title="获取文件信息" class="chapter done " data-progress="3.2.4" style="left: 15.909090909090908%;"></a>
    
        <a href="../content-sharing/beam-files/index.html" title="使用NFC分享文件" class="chapter done " data-progress="3.3" style="left: 16.28787878787879%;"></a>
    
        <a href="../content-sharing/beam-files/sending-files.html" title="发送文件给其他设备" class="chapter done " data-progress="3.3.1" style="left: 16.666666666666668%;"></a>
    
        <a href="../content-sharing/beam-files/receive-files.html" title="接收其他设备的文件" class="chapter done " data-progress="3.3.2" style="left: 17.045454545454547%;"></a>
    
        <a href="../multimedia/index.html" title="多媒体" class="chapter done new-chapter" data-progress="4" style="left: 17.424242424242426%;"></a>
    
        <a href="../multimedia/audio/index.html" title="管理音频播放" class="chapter done " data-progress="4.1" style="left: 17.803030303030305%;"></a>
    
        <a href="../multimedia/audio/volume-playback.html" title="控制你得应用的音量与播放" class="chapter done " data-progress="4.1.1" style="left: 18.181818181818183%;"></a>
    
        <a href="../multimedia/audio/audio-focus.html" title="管理音频焦点" class="chapter done " data-progress="4.1.2" style="left: 18.560606060606062%;"></a>
    
        <a href="../multimedia/audio/audio-output.html" title="兼容音频输出设备" class="chapter done " data-progress="4.1.3" style="left: 18.939393939393938%;"></a>
    
        <a href="../multimedia/camera/index.html" title="拍照" class="chapter done " data-progress="4.2" style="left: 19.318181818181817%;"></a>
    
        <a href="../multimedia/camera/photobasic.html" title="简单的拍照" class="chapter done " data-progress="4.2.1" style="left: 19.696969696969695%;"></a>
    
        <a href="../multimedia/camera/videobasic.html" title="简单的录像" class="chapter done " data-progress="4.2.2" style="left: 20.075757575757574%;"></a>
    
        <a href="../multimedia/camera/cameradirect.html" title="控制相机硬件" class="chapter done " data-progress="4.2.3" style="left: 20.454545454545453%;"></a>
    
        <a href="../multimedia/printing/index.html" title="打印" class="chapter done " data-progress="4.3" style="left: 20.833333333333332%;"></a>
    
        <a href="../multimedia/printing/photos.html" title="打印照片" class="chapter done " data-progress="4.3.1" style="left: 21.21212121212121%;"></a>
    
        <a href="../multimedia/printing/html-docs.html" title="打印HTML文档" class="chapter done " data-progress="4.3.2" style="left: 21.59090909090909%;"></a>
    
        <a href="../multimedia/printing/custom-docs.html" title="打印自定义文档" class="chapter done " data-progress="4.3.3" style="left: 21.96969696969697%;"></a>
    
        <a href="../graphics/index.html" title="图像" class="chapter done new-chapter" data-progress="5" style="left: 22.348484848484848%;"></a>
    
        <a href="../graphics/displaying-bitmaps/index.html" title="高效显示Bitmap" class="chapter done " data-progress="5.1" style="left: 22.727272727272727%;"></a>
    
        <a href="../graphics/displaying-bitmaps/load-bitmap.html" title="高效加载大图" class="chapter done " data-progress="5.1.1" style="left: 23.106060606060606%;"></a>
    
        <a href="../graphics/displaying-bitmaps/process-bitmap.html" title="非UI线程处理Bitmap" class="chapter done " data-progress="5.1.2" style="left: 23.484848484848484%;"></a>
    
        <a href="../graphics/displaying-bitmaps/cache-bitmap.html" title="缓存Bitmap" class="chapter done " data-progress="5.1.3" style="left: 23.863636363636363%;"></a>
    
        <a href="../graphics/displaying-bitmaps/manage-bitmap-memory.html" title="管理Bitmap的内存占用" class="chapter done " data-progress="5.1.4" style="left: 24.242424242424242%;"></a>
    
        <a href="../graphics/displaying-bitmaps/display-bitmap.html" title="在UI上显示Bitmap" class="chapter done " data-progress="5.1.5" style="left: 24.62121212121212%;"></a>
    
        <a href="../graphics/opengl/index.html" title="使用OpenGL ES显示图像" class="chapter done " data-progress="5.2" style="left: 25%;"></a>
    
        <a href="../graphics/opengl/environment.html" title="建立OpenGL ES的环境" class="chapter done " data-progress="5.2.1" style="left: 25.37878787878788%;"></a>
    
        <a href="../graphics/opengl/shapes.html" title="定义Shapes" class="chapter done " data-progress="5.2.2" style="left: 25.757575757575758%;"></a>
    
        <a href="../graphics/opengl/draw.html" title="绘制Shapes" class="chapter done " data-progress="5.2.3" style="left: 26.136363636363637%;"></a>
    
        <a href="../graphics/opengl/projection.html" title="运用投影与相机视图" class="chapter done " data-progress="5.2.4" style="left: 26.515151515151516%;"></a>
    
        <a href="../graphics/opengl/motion.html" title="添加移动" class="chapter done " data-progress="5.2.5" style="left: 26.893939393939394%;"></a>
    
        <a href="../graphics/opengl/touch.html" title="响应触摸事件" class="chapter done " data-progress="5.2.6" style="left: 27.272727272727273%;"></a>
    
        <a href="../animations/index.html" title="动画" class="chapter done new-chapter" data-progress="6" style="left: 27.651515151515152%;"></a>
    
        <a href="../animations/crossfade.html" title="淡入淡出两个View" class="chapter done " data-progress="6.1" style="left: 28.03030303030303%;"></a>
    
        <a href="../animations/screen-slide.html" title="使用ViewPager实现屏幕滑动" class="chapter done " data-progress="6.2" style="left: 28.40909090909091%;"></a>
    
        <a href="../animations/cardflip.html" title="卡片翻转的动画" class="chapter done " data-progress="6.3" style="left: 28.78787878787879%;"></a>
    
        <a href="../animations/zoom.html" title="缩放动画" class="chapter done " data-progress="6.4" style="left: 29.166666666666668%;"></a>
    
        <a href="../animations/layout.html" title="控件切换动画" class="chapter done " data-progress="6.5" style="left: 29.545454545454547%;"></a>
    
        <a href="../connectivity/index.html" title="连接" class="chapter done new-chapter" data-progress="7" style="left: 29.924242424242426%;"></a>
    
        <a href="../connectivity/connect-devices-wireless/index.html" title="无线连接设备" class="chapter done " data-progress="7.1" style="left: 30.303030303030305%;"></a>
    
        <a href="../connectivity/connect-devices-wireless/nsd.html" title="使得网络服务可发现" class="chapter done " data-progress="7.1.1" style="left: 30.681818181818183%;"></a>
    
        <a href="../connectivity/connect-devices-wireless/wifi-direct.html" title="使用WiFi建立P2P连接" class="chapter done " data-progress="7.1.2" style="left: 31.060606060606062%;"></a>
    
        <a href="../connectivity/connect-devices-wireless/nsd-wifi-index.html" title="使用WiFi P2P服务" class="chapter done " data-progress="7.1.3" style="left: 31.439393939393938%;"></a>
    
        <a href="../connectivity/network-ops/index.html" title="网络连接操作" class="chapter done " data-progress="7.2" style="left: 31.818181818181817%;"></a>
    
        <a href="../connectivity/network-ops/connecting.html" title="连接到网络" class="chapter done " data-progress="7.2.1" style="left: 32.196969696969695%;"></a>
    
        <a href="../connectivity/network-ops/managing.html" title="管理使用的网络" class="chapter done " data-progress="7.2.2" style="left: 32.57575757575758%;"></a>
    
        <a href="../connectivity/network-ops/xml.html" title="解析XML数据" class="chapter done " data-progress="7.2.3" style="left: 32.95454545454545%;"></a>
    
        <a href="../connectivity/efficient-downloads/index.html" title="高效下载" class="chapter done " data-progress="7.3" style="left: 33.333333333333336%;"></a>
    
        <a href="../connectivity/efficient-downloads/efficient-network-access.html" title="为网络访问更加高效而优化下载" class="chapter done " data-progress="7.3.1" style="left: 33.71212121212121%;"></a>
    
        <a href="../connectivity/efficient-downloads/regular-update.html" title="最小化更新操作的影响" class="chapter done " data-progress="7.3.2" style="left: 34.09090909090909%;"></a>
    
        <a href="../connectivity/efficient-downloads/redundant-redundant.html" title="避免下载多余的数据" class="chapter done " data-progress="7.3.3" style="left: 34.46969696969697%;"></a>
    
        <a href="../connectivity/efficient-downloads/connectivity-patterns.html" title="根据网络类型改变下载模式" class="chapter done " data-progress="7.3.4" style="left: 34.84848484848485%;"></a>
    
        <a href="../connectivity/sync-adapters/index.html" title="使用Sync Adapter传输数据" class="chapter done " data-progress="7.4" style="left: 35.22727272727273%;"></a>
    
        <a href="../connectivity/sync-adapters/create-authenticator.html" title="创建Stub授权器" class="chapter done " data-progress="7.4.1" style="left: 35.60606060606061%;"></a>
    
        <a href="../connectivity/sync-adapters/create-stub-provider.html" title="创建Stub Content Provider" class="chapter done " data-progress="7.4.2" style="left: 35.984848484848484%;"></a>
    
        <a href="../connectivity/sync-adapters/create-sync-adapter.html" title="创建Sync Adpater" class="chapter done " data-progress="7.4.3" style="left: 36.36363636363637%;"></a>
    
        <a href="../connectivity/sync-adapters/running-sync-adapter.html" title="执行Sync Adpater" class="chapter done " data-progress="7.4.4" style="left: 36.74242424242424%;"></a>
    
        <a href="../connectivity/volley/index.html" title="使用Volley执行网络数据传输" class="chapter done " data-progress="7.5" style="left: 37.121212121212125%;"></a>
    
        <a href="../connectivity/volley/simple.html" title="发送简单的网络请求" class="chapter done " data-progress="7.5.1" style="left: 37.5%;"></a>
    
        <a href="../connectivity/volley/request-queue.html" title="建立请求队列" class="chapter done " data-progress="7.5.2" style="left: 37.878787878787875%;"></a>
    
        <a href="../connectivity/volley/request.html" title="创建标准的网络请求" class="chapter done " data-progress="7.5.3" style="left: 38.25757575757576%;"></a>
    
        <a href="../connectivity/volley/request-custom.html" title="实现自定义的网络请求" class="chapter done " data-progress="7.5.4" style="left: 38.63636363636363%;"></a>
    
        <a href="../cloud/index.html" title="云服务" class="chapter done new-chapter" data-progress="8" style="left: 39.015151515151516%;"></a>
    
        <a href="../cloud/cloudsync/index.html" title="云同步" class="chapter done " data-progress="8.1" style="left: 39.39393939393939%;"></a>
    
        <a href="../cloud/cloudsync/backupapi.html" title="使用备份API" class="chapter done " data-progress="8.1.1" style="left: 39.77272727272727%;"></a>
    
        <a href="../cloud/cloudsync/gcm.html" title="使用Google Cloud Messaging" class="chapter done " data-progress="8.1.2" style="left: 40.15151515151515%;"></a>
    
        <a href="../cloud/cloudsave/index.html" title="解决云同步的保存冲突" class="chapter done " data-progress="8.2" style="left: 40.53030303030303%;"></a>
    
        <a href="../contacts-provider/index.html" title="用户信息" class="chapter done new-chapter" data-progress="9" style="left: 40.90909090909091%;"></a>
    
        <a href="../contacts-provider/retrieve-names.html" title="获取联系人列表" class="chapter done " data-progress="9.1" style="left: 41.28787878787879%;"></a>
    
        <a href="../contacts-provider/retrieve-detail.html" title="获取联系人详情" class="chapter done " data-progress="9.2" style="left: 41.666666666666664%;"></a>
    
        <a href="../contacts-provider/modify-data.html" title="修改联系人信息" class="chapter done " data-progress="9.3" style="left: 42.04545454545455%;"></a>
    
        <a href="../contacts-provider/display-badge.html" title="显示联系人头像" class="chapter done " data-progress="9.4" style="left: 42.42424242424242%;"></a>
    
        <a href="../location/index.html" title="位置信息" class="chapter done " data-progress="10" style="left: 42.803030303030305%;"></a>
    
        <a href="../location/retrieve-current.html" title="获取当前位置" class="chapter done " data-progress="10.1" style="left: 43.18181818181818%;"></a>
    
        <a href="../location/retrieve-location-updates.html" title="获取位置更新" class="chapter done " data-progress="10.2" style="left: 43.56060606060606%;"></a>
    
        <a href="../location/display-address.html" title="显示位置地址" class="chapter done " data-progress="10.3" style="left: 43.93939393939394%;"></a>
    
        <a href="../location/geofencing.html" title="创建并监视异常区域" class="chapter done " data-progress="10.4" style="left: 44.31818181818182%;"></a>
    
        <a href="../location/activity-recognition.html" title="识别用户的当下活动" class="chapter  " data-progress="10.5" style="left: 44.696969696969695%;"></a>
    
        <a href="../location/location-testing.html" title="使用模拟位置进行测试" class="chapter  " data-progress="10.6" style="left: 45.07575757575758%;"></a>
    
        <a href="../wearables/index.html" title="为可穿戴设备创建应用" class="chapter  " data-progress="11" style="left: 45.45454545454545%;"></a>
    
        <a href="../wearables/notifications/index.html" title="赋予Notification可穿戴特性" class="chapter  " data-progress="11.1" style="left: 45.833333333333336%;"></a>
    
        <a href="../wearables/notifications/creating.html" title="创建Notification" class="chapter  " data-progress="11.1.1" style="left: 46.21212121212121%;"></a>
    
        <a href="../wearables/notifications/voice-input.html" title="在Notifcation中接收语音输入" class="chapter  " data-progress="11.1.2" style="left: 46.59090909090909%;"></a>
    
        <a href="../wearables/notifications/pages.html" title="为Notification添加显示页面" class="chapter  " data-progress="11.1.3" style="left: 46.96969696969697%;"></a>
    
        <a href="../wearables/notifications/stacks.html" title="以Stack的方式显示Notifications" class="chapter  " data-progress="11.1.4" style="left: 47.34848484848485%;"></a>
    
        <a href="../wearables/apps/index.html" title="创建可穿戴的应用" class="chapter  " data-progress="11.2" style="left: 47.72727272727273%;"></a>
    
        <a href="../wearables/apps/creating.html" title="创建并执行可穿戴应用" class="chapter  " data-progress="11.2.1" style="left: 48.10606060606061%;"></a>
    
        <a href="../wearables/apps/layouts.html" title="创建自定义的布局" class="chapter  " data-progress="11.2.2" style="left: 48.484848484848484%;"></a>
    
        <a href="../wearables/apps/voice.html" title="添加语音能力" class="chapter  " data-progress="11.2.3" style="left: 48.86363636363637%;"></a>
    
        <a href="../wearables/apps/packaging.html" title="打包可穿戴应用" class="chapter  " data-progress="11.2.4" style="left: 49.24242424242424%;"></a>
    
        <a href="../wearables/apps/bt-debugging.html" title="通过蓝牙进行调试" class="chapter  " data-progress="11.2.5" style="left: 49.621212121212125%;"></a>
    
        <a href="../wearables/data-layer/index.html" title="发送并同步数据" class="chapter  " data-progress="11.3" style="left: 50%;"></a>
    
        <a href="../wearables/data-layer/accessing.html" title="访问可穿戴数据层" class="chapter  " data-progress="11.3.1" style="left: 50.378787878787875%;"></a>
    
        <a href="../wearables/data-layer/data-items.html" title="同步数据单元" class="chapter  " data-progress="11.3.2" style="left: 50.75757575757576%;"></a>
    
        <a href="../wearables/data-layer/assets.html" title="传输资源" class="chapter  " data-progress="11.3.3" style="left: 51.13636363636363%;"></a>
    
        <a href="../wearables/data-layer/messages.html" title="发送与接收消息" class="chapter  " data-progress="11.3.4" style="left: 51.515151515151516%;"></a>
    
        <a href="../wearables/data-layer/events.html" title="处理数据层的事件" class="chapter  " data-progress="11.3.5" style="left: 51.89393939393939%;"></a>
    
        <a href="../ux/index.html" title="交互" class="chapter  " data-progress="12" style="left: 52.27272727272727%;"></a>
    
        <a href="../ux/design-nav/index.html" title="设计高效的导航" class="chapter  " data-progress="12.1" style="left: 52.65151515151515%;"></a>
    
        <a href="../ux/design-nav/screen-planning.html" title="规划屏幕界面与他们之间的关系" class="chapter  " data-progress="12.1.1" style="left: 53.03030303030303%;"></a>
    
        <a href="../ux/design-nav/multi-sizes.html" title="为多种大小的屏幕进行规划" class="chapter  " data-progress="12.1.2" style="left: 53.40909090909091%;"></a>
    
        <a href="../ux/design-nav/descendant-lateral.html" title="提供向下与侧滑的导航" class="chapter  " data-progress="12.1.3" style="left: 53.78787878787879%;"></a>
    
        <a href="../ux/design-nav/ancestral-temporal.html" title="提供向上与暂时的导航" class="chapter  " data-progress="12.1.4" style="left: 54.166666666666664%;"></a>
    
        <a href="../ux/design-nav/wireframing.html" title="综合上面所有的导航" class="chapter  " data-progress="12.1.5" style="left: 54.54545454545455%;"></a>
    
        <a href="../ux/implement-nav/index.html" title="实现高效的导航" class="chapter  " data-progress="12.2" style="left: 54.92424242424242%;"></a>
    
        <a href="../ux/implement-nav/lateral.html" title="使用Tabs创建Swipe视图" class="chapter  " data-progress="12.2.1" style="left: 55.303030303030305%;"></a>
    
        <a href="../ux/implement-nav/nav-drawer.html" title="创建抽屉导航" class="chapter  " data-progress="12.2.2" style="left: 55.68181818181818%;"></a>
    
        <a href="../ux/implement-nav/ancestral.html" title="提供向上的导航" class="chapter  " data-progress="12.2.3" style="left: 56.06060606060606%;"></a>
    
        <a href="../ux/implement-nav/temporal.html" title="提供向后的导航" class="chapter  " data-progress="12.2.4" style="left: 56.43939393939394%;"></a>
    
        <a href="../ux/implement-nav/descendant.html" title="实现向下的导航" class="chapter  " data-progress="12.2.5" style="left: 56.81818181818182%;"></a>
    
        <a href="../ux/notify-user/index.html" title="通知提示用户" class="chapter  " data-progress="12.3" style="left: 57.196969696969695%;"></a>
    
        <a href="../ux/notify-user/build-notification.html" title="建立Notification" class="chapter  " data-progress="12.3.1" style="left: 57.57575757575758%;"></a>
    
        <a href="../ux/notify-user/nav.html" title="当启动Activity时保留导航" class="chapter  " data-progress="12.3.2" style="left: 57.95454545454545%;"></a>
    
        <a href="../ux/notify-user/update-notification.html" title="更新Notification" class="chapter  " data-progress="12.3.3" style="left: 58.333333333333336%;"></a>
    
        <a href="../ux/notify-user/expand-notification.html" title="使用BigView风格" class="chapter  " data-progress="12.3.4" style="left: 58.71212121212121%;"></a>
    
        <a href="../ux/notify-user/progess-notification.html" title="显示Notification进度" class="chapter  " data-progress="12.3.5" style="left: 59.09090909090909%;"></a>
    
        <a href="../ux/search/index.html" title="增加搜索功能" class="chapter  " data-progress="12.4" style="left: 59.46969696969697%;"></a>
    
        <a href="../ux/search/setup.html" title="建立搜索界面" class="chapter  " data-progress="12.4.1" style="left: 59.84848484848485%;"></a>
    
        <a href="../ux/search/search.html" title="保存并搜索数据" class="chapter  " data-progress="12.4.2" style="left: 60.22727272727273%;"></a>
    
        <a href="../ux/search/back-compat.html" title="保持向下兼容" class="chapter  " data-progress="12.4.3" style="left: 60.60606060606061%;"></a>
    
        <a href="../ux/app-indexing/index.html" title="使得你的App内容可被Google搜索" class="chapter  " data-progress="12.5" style="left: 60.984848484848484%;"></a>
    
        <a href="../ux/app-indexing/deep-linking.html" title="为App内容开启深度链接" class="chapter  " data-progress="12.5.1" style="left: 61.36363636363637%;"></a>
    
        <a href="../ux/app-indexing/enable-app-indexing.html" title="为索引指定App内容" class="chapter  " data-progress="12.5.2" style="left: 61.74242424242424%;"></a>
    
        <a href="../ui/index.html" title="UI" class="chapter  " data-progress="13" style="left: 62.121212121212125%;"></a>
    
        <a href="../ui/multiscreen/index.html" title="为多屏幕设计" class="chapter  " data-progress="13.1" style="left: 62.5%;"></a>
    
        <a href="../ui/multiscreen/screen-sizes.html" title="兼容不同的屏幕大小" class="chapter  " data-progress="13.1.1" style="left: 62.878787878787875%;"></a>
    
        <a href="../ui/multiscreen/screen-desities.html" title="兼容不同的屏幕密度" class="chapter  " data-progress="13.1.2" style="left: 63.25757575757576%;"></a>
    
        <a href="../ui/multiscreen/adapt-ui.html" title="实现可适应的UI" class="chapter  " data-progress="13.1.3" style="left: 63.63636363636363%;"></a>
    
        <a href="../ui/tv/index.html" title="为TV进行设计" class="chapter  " data-progress="13.2" style="left: 64.01515151515152%;"></a>
    
        <a href="../ui/tv/optimize-layouts-tv.html" title="为TV优化Layout" class="chapter  " data-progress="13.2.1" style="left: 64.39393939393939%;"></a>
    
        <a href="../ui/tv/optimize-nav-tv.html" title="为TV优化导航" class="chapter  " data-progress="13.2.2" style="left: 64.77272727272727%;"></a>
    
        <a href="../ui/tv/unsupport-features-tv.html" title="处理不支持TV的功能" class="chapter  " data-progress="13.2.3" style="left: 65.15151515151516%;"></a>
    
        <a href="../ui/custom-view/index.html" title="创建自定义View" class="chapter  " data-progress="13.3" style="left: 65.53030303030303%;"></a>
    
        <a href="../ui/custom-view/create-view.html" title="创建自定义的View类" class="chapter  " data-progress="13.3.1" style="left: 65.9090909090909%;"></a>
    
        <a href="../ui/custom-view/custom-draw.html" title="实现自定义View的绘制" class="chapter  " data-progress="13.3.2" style="left: 66.28787878787878%;"></a>
    
        <a href="../ui/custom-view/make-interactive.html" title="使得View可交互" class="chapter  " data-progress="13.3.3" style="left: 66.66666666666667%;"></a>
    
        <a href="../ui/custom-view/optimize-view.html" title="优化自定义View" class="chapter  " data-progress="13.3.4" style="left: 67.04545454545455%;"></a>
    
        <a href="../ui/backward-compatible-ui/index.html" title="创建向后兼容的UI" class="chapter  " data-progress="13.4" style="left: 67.42424242424242%;"></a>
    
        <a href="../ui/backward-compatible-ui/abstract.html" title="抽象新的APIs" class="chapter  " data-progress="13.4.1" style="left: 67.8030303030303%;"></a>
    
        <a href="../ui/backward-compatible-ui/new-impl.html" title="代理至新的APIs" class="chapter  " data-progress="13.4.2" style="left: 68.18181818181819%;"></a>
    
        <a href="../ui/backward-compatible-ui/older-impl.html" title="使用旧的APIs实现新API的效果" class="chapter  " data-progress="13.4.3" style="left: 68.56060606060606%;"></a>
    
        <a href="../ui/backward-compatible-ui/using-component.html" title="使用版本敏感的组件" class="chapter  " data-progress="13.4.4" style="left: 68.93939393939394%;"></a>
    
        <a href="../ui/accessibility/index.html" title="实现辅助功能" class="chapter  " data-progress="13.5" style="left: 69.31818181818181%;"></a>
    
        <a href="../ui/accessibility/accessible-app.html" title="开发辅助程序" class="chapter  " data-progress="13.5.1" style="left: 69.6969696969697%;"></a>
    
        <a href="../ui/accessibility/accessible-service.html" title="开发辅助服务" class="chapter  " data-progress="13.5.2" style="left: 70.07575757575758%;"></a>
    
        <a href="../ui/system-ui/index.html" title="管理系统UI" class="chapter  " data-progress="13.6" style="left: 70.45454545454545%;"></a>
    
        <a href="../ui/system-ui/dim.html" title="淡化系统Bar" class="chapter  " data-progress="13.6.1" style="left: 70.83333333333333%;"></a>
    
        <a href="../ui/system-ui/hide-ui.html" title="隐藏系统Bar" class="chapter  " data-progress="13.6.2" style="left: 71.21212121212122%;"></a>
    
        <a href="../ui/system-ui/hide-nav.html" title="隐藏导航Bar" class="chapter  " data-progress="13.6.3" style="left: 71.5909090909091%;"></a>
    
        <a href="../ui/system-ui/immersive.html" title="全屏沉浸式应用" class="chapter  " data-progress="13.6.4" style="left: 71.96969696969697%;"></a>
    
        <a href="../ui/system-ui/visibility.html" title="响应UI可见性的变化" class="chapter  " data-progress="13.6.5" style="left: 72.34848484848484%;"></a>
    
        <a href="../input/index.html" title="用户输入" class="chapter  " data-progress="14" style="left: 72.72727272727273%;"></a>
    
        <a href="../input/gestures/index.html" title="使用触摸手势" class="chapter  " data-progress="14.1" style="left: 73.10606060606061%;"></a>
    
        <a href="../input/gestures/detector.html" title="检测常用的手势" class="chapter  " data-progress="14.1.1" style="left: 73.48484848484848%;"></a>
    
        <a href="../input/gestures/movement.html" title="跟踪手势移动" class="chapter  " data-progress="14.1.2" style="left: 73.86363636363636%;"></a>
    
        <a href="../input/gestures/scroll.html" title="Scroll手势动画" class="chapter  " data-progress="14.1.3" style="left: 74.24242424242425%;"></a>
    
        <a href="../input/gestures/multi.html" title="处理多触摸手势" class="chapter  " data-progress="14.1.4" style="left: 74.62121212121212%;"></a>
    
        <a href="../input/gestures/scale.html" title="拖拽与缩放" class="chapter  " data-progress="14.1.5" style="left: 75%;"></a>
    
        <a href="../input/gestures/viewgroup.html" title="管理ViewGroup中的触摸事件" class="chapter  " data-progress="14.1.6" style="left: 75.37878787878788%;"></a>
    
        <a href="../input/keyboard-input/index.html" title="处理键盘输入" class="chapter  " data-progress="14.2" style="left: 75.75757575757575%;"></a>
    
        <a href="../input/keyboard-input/type.html" title="指定输入法类型" class="chapter  " data-progress="14.2.1" style="left: 76.13636363636364%;"></a>
    
        <a href="../input/keyboard-input/visibility.html" title="处理输入法可见性" class="chapter  " data-progress="14.2.2" style="left: 76.51515151515152%;"></a>
    
        <a href="../input/keyboard-input/navigation.html" title="兼容硬件导航" class="chapter  " data-progress="14.2.3" style="left: 76.89393939393939%;"></a>
    
        <a href="../input/keyboard-input/commands.html" title="处理按键动作" class="chapter  " data-progress="14.2.4" style="left: 77.27272727272727%;"></a>
    
        <a href="../input/game-controller/index.html" title="兼容游戏控制器" class="chapter  " data-progress="14.3" style="left: 77.65151515151516%;"></a>
    
        <a href="../input/game-controller/controller-inputs.html" title="处理控制器输入动作" class="chapter  " data-progress="14.3.1" style="left: 78.03030303030303%;"></a>
    
        <a href="../input/game-controller/compatibility.html" title="支持不同的Android系统版本" class="chapter  " data-progress="14.3.2" style="left: 78.4090909090909%;"></a>
    
        <a href="../input/game-controller/multi-controller.html" title="支持多个控制器" class="chapter  " data-progress="14.3.3" style="left: 78.78787878787878%;"></a>
    
        <a href="../background-jobs/index.html" title="后台任务" class="chapter  " data-progress="15" style="left: 79.16666666666667%;"></a>
    
        <a href="../background-jobs/run-background-service/index.html" title="在IntentService中执行后台任务" class="chapter  " data-progress="15.1" style="left: 79.54545454545455%;"></a>
    
        <a href="../background-jobs/run-background-service/create-service.html" title="创建IntentService" class="chapter  " data-progress="15.1.1" style="left: 79.92424242424242%;"></a>
    
        <a href="../background-jobs/run-background-service/send-request.html" title="发送工作任务到IntentService" class="chapter  " data-progress="15.1.2" style="left: 80.3030303030303%;"></a>
    
        <a href="../background-jobs/run-background-service/report-status.html" title="报告后台任务执行状态" class="chapter  " data-progress="15.1.3" style="left: 80.68181818181819%;"></a>
    
        <a href="../background-jobs/load-data-background/index.html" title="使用CursorLoader在后台加载数据" class="chapter  " data-progress="15.2" style="left: 81.06060606060606%;"></a>
    
        <a href="../background-jobs/load-data-background/setup-loader.html" title="使用CursorLoader执行查询任务" class="chapter  " data-progress="15.2.1" style="left: 81.43939393939394%;"></a>
    
        <a href="../background-jobs/load-data-background/handle-result.html" title="处理查询的结果" class="chapter  " data-progress="15.2.2" style="left: 81.81818181818181%;"></a>
    
        <a href="../background-jobs/scheduling/index.html" title="管理设备的唤醒状态" class="chapter  " data-progress="15.3" style="left: 82.1969696969697%;"></a>
    
        <a href="../background-jobs/scheduling/wake-lock.html" title="保持设备的唤醒" class="chapter  " data-progress="15.3.1" style="left: 82.57575757575758%;"></a>
    
        <a href="../background-jobs/scheduling/alarms.html" title="制定重复定时的任务" class="chapter  " data-progress="15.3.2" style="left: 82.95454545454545%;"></a>
    
        <a href="../performance/index.html" title="性能优化" class="chapter  " data-progress="16" style="left: 83.33333333333333%;"></a>
    
        <a href="../performance/memory.html" title="管理应用的内存" class="chapter  " data-progress="16.1" style="left: 83.71212121212122%;"></a>
    
        <a href="../performance/performance-tips.html" title="性能优化Tips" class="chapter  " data-progress="16.2" style="left: 84.0909090909091%;"></a>
    
        <a href="../performance/improving-layouts/index.html" title="提升Layout的性能" class="chapter  " data-progress="16.3" style="left: 84.46969696969697%;"></a>
    
        <a href="../performance/improving-layouts/optimizing-layout.html" title="优化layout的层级" class="chapter  " data-progress="16.3.1" style="left: 84.84848484848484%;"></a>
    
        <a href="../performance/improving-layouts/reuse-layouts.html" title="使用include标签重用layouts" class="chapter  " data-progress="16.3.2" style="left: 85.22727272727273%;"></a>
    
        <a href="../performance/improving-layouts/loading-ondemand.html" title="按需加载视图" class="chapter  " data-progress="16.3.3" style="left: 85.60606060606061%;"></a>
    
        <a href="../performance/improving-layouts/smooth-scrolling.html" title="使得ListView滑动顺畅" class="chapter  " data-progress="16.3.4" style="left: 85.98484848484848%;"></a>
    
        <a href="../performance/monitor-device-state/index.html" title="优化电池寿命" class="chapter  " data-progress="16.4" style="left: 86.36363636363636%;"></a>
    
        <a href="../performance/monitor-device-state/battery-monitor.html" title="监测电量与充电状态" class="chapter  " data-progress="16.4.1" style="left: 86.74242424242425%;"></a>
    
        <a href="../performance/monitor-device-state/docking-monitor.html" title="判断与监测Docking状态" class="chapter  " data-progress="16.4.2" style="left: 87.12121212121212%;"></a>
    
        <a href="../performance/monitor-device-state/connectivity-monitor.html" title="判断与监测网络连接状态" class="chapter  " data-progress="16.4.3" style="left: 87.5%;"></a>
    
        <a href="../performance/monitor-device-state/manifest-receivers.html" title="根据需要操作Broadcast接受者" class="chapter  " data-progress="16.4.4" style="left: 87.87878787878788%;"></a>
    
        <a href="../performance/multi-threads/index.html" title="多线程操作" class="chapter  " data-progress="16.5" style="left: 88.25757575757575%;"></a>
    
        <a href="../performance/multi-threads/define-runnable.html" title="在一个线程中执行一段特定的代码" class="chapter  " data-progress="16.5.1" style="left: 88.63636363636364%;"></a>
    
        <a href="../performance/multi-threads/create-threadpool.html" title="为多线程创建线程池" class="chapter  " data-progress="16.5.2" style="left: 89.01515151515152%;"></a>
    
        <a href="../performance/multi-threads/run-code.html" title="在线程池中的一个线程里执行代码" class="chapter  " data-progress="16.5.3" style="left: 89.39393939393939%;"></a>
    
        <a href="../performance/multi-threads/communicate-ui.html" title="与UI线程通信" class="chapter  " data-progress="16.5.4" style="left: 89.77272727272727%;"></a>
    
        <a href="../performance/perf-anr/index.html" title="避免出现程序无响应ANR" class="chapter  " data-progress="16.7" style="left: 90.15151515151516%;"></a>
    
        <a href="../performance/perf-jni/index.html" title="JNI Tips" class="chapter  " data-progress="16.8" style="left: 90.53030303030303%;"></a>
    
        <a href="../performance/smp/index.html" title="SMP for Android" class="chapter  " data-progress="16.9" style="left: 90.9090909090909%;"></a>
    
        <a href="../security/index.html" title="安全与隐私" class="chapter  " data-progress="17" style="left: 91.28787878787878%;"></a>
    
        <a href="../security/security-tips.html" title="Security Tips" class="chapter  " data-progress="17.1" style="left: 91.66666666666667%;"></a>
    
        <a href="../security/security-ssl.html" title="使用HTTPS与SSL" class="chapter  " data-progress="17.2" style="left: 92.04545454545455%;"></a>
    
        <a href="../security/enterprise.html" title="企业版App" class="chapter  " data-progress="17.3" style="left: 92.42424242424242%;"></a>
    
        <a href="../testing/index.html" title="测试程序" class="chapter  " data-progress="18" style="left: 92.8030303030303%;"></a>
    
        <a href="../testing/activity-testing/index.html" title="测试你的Activity" class="chapter  " data-progress="18.1" style="left: 93.18181818181819%;"></a>
    
        <a href="../testing/activity-testing/prepare-activity-testing.html" title="建立测试环境" class="chapter  " data-progress="18.1.1" style="left: 93.56060606060606%;"></a>
    
        <a href="../testing/activity-testing/activity-basic-testing.html" title="创建与执行测试用例" class="chapter  " data-progress="18.1.2" style="left: 93.93939393939394%;"></a>
    
        <a href="../testing/activity-testing/activity-ui-testing.html" title="测试UI组件" class="chapter  " data-progress="18.1.3" style="left: 94.31818181818181%;"></a>
    
        <a href="../testing/activity-testing/activity-unit-testing.html" title="创建单元测试" class="chapter  " data-progress="18.1.4" style="left: 94.6969696969697%;"></a>
    
        <a href="../testing/activity-testing/activity-function-testing.html" title="创建功能测试" class="chapter  " data-progress="18.1.5" style="left: 95.07575757575758%;"></a>
    
        <a href="../distribute/index.html" title="分发与盈利" class="chapter  " data-progress="19" style="left: 95.45454545454545%;"></a>
    
        <a href="../distribute/in-app-billing/index.html" title="售卖App内置产品" class="chapter  " data-progress="19.1" style="left: 95.83333333333333%;"></a>
    
        <a href="../distribute/in-app-billing/prepare-iab-app.html" title="准备你的App" class="chapter  " data-progress="19.1.1" style="left: 96.21212121212122%;"></a>
    
        <a href="../distribute/in-app-billing/list-iab-products.html" title="建立售卖的产品" class="chapter  " data-progress="19.1.2" style="left: 96.5909090909091%;"></a>
    
        <a href="../distribute/in-app-billing/purchase-iab-products.html" title="购买产品" class="chapter  " data-progress="19.1.3" style="left: 96.96969696969697%;"></a>
    
        <a href="../distribute/in-app-billing/test-iab-app.html" title="测试你的App" class="chapter  " data-progress="19.1.4" style="left: 97.34848484848484%;"></a>
    
        <a href="../distribute/multi-apks/index.html" title="维护多个APK" class="chapter  " data-progress="19.2" style="left: 97.72727272727273%;"></a>
    
        <a href="../distribute/multi-apks/api.html" title="为不同API Level创建多个APK" class="chapter  " data-progress="19.2.1" style="left: 98.10606060606061%;"></a>
    
        <a href="../distribute/multi-apks/screen-size.html" title="为不同屏幕大小创建多个APK" class="chapter  " data-progress="19.2.2" style="left: 98.48484848484848%;"></a>
    
        <a href="../distribute/multi-apks/texture.html" title="为不同的GL Texture创建多个APK" class="chapter  " data-progress="19.2.3" style="left: 98.86363636363636%;"></a>
    
        <a href="../distribute/multi-apks/multiple.html" title="为2种以上的维度创建多个APK" class="chapter  " data-progress="19.2.4" style="left: 99.24242424242425%;"></a>
    
        <a href="../distribute/monetization/index.html" title="App盈利" class="chapter  " data-progress="19.3" style="left: 99.62121212121212%;"></a>
    
        <a href="../distribute/monetization/ads-and-ux.html" title="在不影响用户体验的前提下添加广告" class="chapter  " data-progress="19.3.1" style="left: 100%;"></a>
    
    </div>
</div>

                <div class="page-inner">
                
                    <section class="normal" id="section-gitbook_160">
                    
                        <blockquote>
<p>编写:<a href="https://github.com/penkzhou" target="_blank">penkzhou</a></p>
<p>校对:</p>
</blockquote>
<h1 id="-">创建并监视异常区域</h1>
<p>地理围栏将用户当前位置感知和附件地点特征感知相结合，定义了用户对位置的接近程度。为了让一个位置有感知，你必须确定这个位置的经纬度。为了度量用户对位置的接近程度，你需要添加一个半径。综合经纬度和半径即可确定一个地理围栏。当然你可以一次性定义多个地理围栏。</p>
<p>Location Services将一个地理围栏看成是一片区域而不是一个点和一个接近程度。这样可以让它去探测用户是否进入或者正在某个地理围栏中。对于每个地理围栏，你可以让Location Services给你发送进入或者退出地理围栏事件。你还可以通过设置一一个毫秒级别的有效时间来限制地理围栏的生命周期。当地理围栏失效后，Location Services会自动移除这个地理围栏。</p>
<h2 id="-">请求地理围栏监视</h2>
<p>请求地理围栏监视的第一步就是设置必要的权限。在使用地理围栏时，你必须设置<a href="http://developer.android.com/reference/android/Manifest.permission.html#ACCESS_FINE_LOCATION" target="_blank">ACCESS_FINE_LOCATION</a>权限。添加如下代码即可：</p>
<pre><code class="lang-java">&lt;uses-permission android:name=<span class="hljs-string">"android.permission.ACCESS_FINE_LOCATION"</span>/&gt;
</code></pre>
<h3 id="-google-play-services-">检查Google Play Services是否可用</h3>
<p>位置服务是Google Play services 中的一部分。由于很难预料用户设备的状态，所以你在尝试连接位置服务之前应该要检测你的设备是否安装了Google Play services安装包。为了检测这个安装包是否被安装，你可以调用<a href="http://developer.android.com/reference/com/google/android/gms/common/GooglePlayServicesUtil.html#isGooglePlayServicesAvailable(android.content.Context" target="_blank">GooglePlayServicesUtil.isGooglePlayServicesAvailable()</a>，这个方法将会返回一个结果代码。你可以通过查询<a href="http://developer.android.com/reference/com/google/android/gms/common/ConnectionResult.html" target="_blank">ConnectionResult</a>的参考文档中结果代码列表来理解对应的结果代码。如果你碰到了错误，你可以调用<a href="http://developer.android.com/reference/com/google/android/gms/common/GooglePlayServicesUtil.html#getErrorDialog(int, android.app.Activity, int" target="_blank">GooglePlayServicesUtil.getErrorDialog()</a>)获取本地化的对话框来提示用户采取适当地行为，接着你需要将这个对话框置于一个<a href="http://developer.android.com/reference/android/support/v4/app/DialogFragment.html" target="_blank">DialogFragment</a>中显示。这个对话框可以让用户去纠正这个问题，这个时候Google Services可以将结果返回给你的activity。为了处理这个结果，重写<a href="http://developer.android.com/reference/android/app/Activity.html#onActivityResult(int, int, android.content.Intent" target="_blank">onActivityResult()</a>)即可。</p>
<blockquote>
<p><strong>注意:</strong> 为了让你的应用能够兼容 Android 1.6 之后的版本，用来显示DialogFragment的必须是FragmentActivity而不是之前的Activity。使用FragmentActivity同样可以调用 getSupportFragmentManager() 方法来显示 DialogFragment。</p>
</blockquote>
<p>因为你的代码里通常会不止一次地检测Google Play services是否安装, 为了方便，可以定义一个方法来封装这种检测行为。下面的代码片段包含了所有检测Google Play services是否安装需要用到的代码：</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MainActivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FragmentActivity</span> {</span>
    ...
    <span class="hljs-comment">//全局变量</span>
    <span class="hljs-comment">/*
     * 定义一个发送给Google Play services的请求代码
     * 这个代码将会在Activity.onActivityResult的方法中返回
     */</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">int</span>
            CONNECTION_FAILURE_RESOLUTION_REQUEST = <span class="hljs-number">9000</span>;
    ...
    <span class="hljs-comment">// 定义一个显示错误对话框的DialogFragment</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ErrorDialogFragment</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">DialogFragment</span> {</span>
        <span class="hljs-comment">// 表示错误对话框的全局属性</span>
        <span class="hljs-keyword">private</span> Dialog mDialog;
        <span class="hljs-comment">// 默认的构造函数，将 dialog 属性设为空</span>
        <span class="hljs-keyword">public</span> <span class="hljs-title">ErrorDialogFragment</span>() {
            <span class="hljs-keyword">super</span>();
            mDialog = <span class="hljs-keyword">null</span>;
        }
        <span class="hljs-comment">// 设置要显示的dialog</span>
        <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setDialog</span>(Dialog dialog) {
            mDialog = dialog;
        }
        <span class="hljs-comment">// 返回一个 Dialog 给 DialogFragment.</span>
        <span class="hljs-annotation">@Override</span>
        <span class="hljs-keyword">public</span> Dialog <span class="hljs-title">onCreateDialog</span>(Bundle savedInstanceState) {
            <span class="hljs-keyword">return</span> mDialog;
        }
    }
    ...
    <span class="hljs-comment">/*
     * 处理来自Google Play services 发给FragmentActivity的结果
     *
     */</span>
    <span class="hljs-annotation">@Override</span>
    <span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onActivityResult</span>(
            <span class="hljs-keyword">int</span> requestCode, <span class="hljs-keyword">int</span> resultCode, Intent data) {
        <span class="hljs-comment">// 根据请求代码来决定做什么</span>
        <span class="hljs-keyword">switch</span> (requestCode) {
            ...
            <span class="hljs-keyword">case</span> CONNECTION_FAILURE_RESOLUTION_REQUEST :
            <span class="hljs-comment">/*
             * 如果结果代码是 Activity.RESULT_OK, 尝试重新连接
             *
             */</span>
                <span class="hljs-keyword">switch</span> (resultCode) {
                    <span class="hljs-keyword">case</span> Activity.RESULT_OK :
                    <span class="hljs-comment">/*
                     * 尝试重新请求
                     */</span>
                    ...
                    <span class="hljs-keyword">break</span>;
                }
            ...
        }
     }
    ...
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">servicesConnected</span>() {
        <span class="hljs-comment">// 检测Google Play services 是否可用</span>
        <span class="hljs-keyword">int</span> resultCode =
                GooglePlayServicesUtil.
                        isGooglePlayServicesAvailable(<span class="hljs-keyword">this</span>);
        <span class="hljs-comment">// 如果 Google Play services 可用</span>
        <span class="hljs-keyword">if</span> (ConnectionResult.SUCCESS == resultCode) {
            <span class="hljs-comment">// 在 debug 模式下, 记录程序日志</span>
            Log.d(<span class="hljs-string">"Location Updates"</span>,
                    <span class="hljs-string">"Google Play services is available."</span>);
            <span class="hljs-comment">// Continue</span>
            <span class="hljs-keyword">return</span> <span class="hljs-keyword">true</span>;
        <span class="hljs-comment">// 因为某些原因Google Play services 不可用</span>
        } <span class="hljs-keyword">else</span> {
            <span class="hljs-comment">// 获取error code</span>
            <span class="hljs-keyword">int</span> errorCode = connectionResult.getErrorCode();
            <span class="hljs-comment">// 从Google Play services 获取 error dialog</span>
            Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(
                    errorCode,
                    <span class="hljs-keyword">this</span>,
                    CONNECTION_FAILURE_RESOLUTION_REQUEST);

            <span class="hljs-comment">// 如果 Google Play services可以提供一个error dialog</span>
            <span class="hljs-keyword">if</span> (errorDialog != <span class="hljs-keyword">null</span>) {
                <span class="hljs-comment">// 为这个error dialog 创建一个新的DialogFragment</span>
                ErrorDialogFragment errorFragment =
                        <span class="hljs-keyword">new</span> ErrorDialogFragment();
                <span class="hljs-comment">// 在DialogFragment中设置dialog</span>
                errorFragment.setDialog(errorDialog);
                <span class="hljs-comment">// 在DialogFragment中显示error dialog</span>
                errorFragment.show(getSupportFragmentManager(),
                        <span class="hljs-string">"Geofence Detection"</span>);
            }
        }
    }
    ...
}
</code></pre>
<p>下面的代码片段使用了这个方法来检查Google Play services是否可用。</p>
<p>要使用地理围栏，你得先定义你要监控的地理围栏。通常你可以在本地保存地理围栏数据或者从互联网上获取地理围栏数据，然后你需要发送一个由<a href="http://developer.android.com/reference/com/google/android/gms/location/Geofence.Builder.html" target="_blank">Geofence.Builder</a>创建的<a href="http://developer.android.com/reference/com/google/android/gms/location/Geofence.html" target="_blank">Geofence</a>对象给Location Services。每一个<a href="http://developer.android.com/reference/com/google/android/gms/location/Geofence.html" target="_blank">Geofence</a>对象都包括了以下数据：</p>
<p>精度, 纬度和半径</p>
<ul>
<li>为地理围栏定义一个圆形区域。使用经纬度标记一个兴趣地点，然后使用半径定义地理围栏有效区域。半径越大，用户越有可能触发地理围栏的警报。例如，为一个家庭灯具地理围栏应用设置一个大的半径，这样当用户回家就可能触发地理围栏，然后灯就亮了。</li>
</ul>
<p>有效时间</p>
<ul>
<li>地理围栏保持激活状态的时间。一旦达到了有效时间，Location Services会删除这个地理围栏。大部分时候，你都应该为你的应用设置一个有效时间，但对于家居或者工作空间等类型的应用，可能设置需要永久的地理围栏。nces for the user&#39;s home or place of work.</li>
</ul>
<p>触发事件类型</p>
<ul>
<li>Location Services 能探测到用户进入地理围栏的有效范围内或者走出有效范围的事件。</li>
</ul>
<p>地理围栏 ID</p>
<ul>
<li>一个与地理围栏一同保存的字符串。你必须保证这个字符串唯一，这样你就可以使用它从Location Services的记录里来移除特定地理围栏。</li>
</ul>
<h3 id="-">定义地理围栏存储</h3>
<p>一个地理围栏应用需要将地理围栏数据做持久化的读写。但是你不能使用<a href="http://developer.android.com/reference/com/google/android/gms/location/Geofence.html" target="_blank">Geofence</a> 进行这样的操作；你可以使用数据库等方式来保存地理围栏的相关数据。</p>
<p>作为一个保存地理围栏数据的实例，下面的代码片段定义了两个使用<a href="http://developer.android.com/reference/android/content/SharedPreferences.html" target="_blank">SharedPreferences</a> 的类来进行地理围栏的数据持久化。 <code>SimpleGeofence</code>类， 类似于一条数据库记录，为一个<a href="http://developer.android.com/reference/com/google/android/gms/location/Geofence.html" target="_blank">Geofence</a> 对象存储数据。<code>SimpleGeofenceStore</code>类，类似于一个数据库，对<code>SimpleGeofence</code> 的读写应用到 <a href="http://developer.android.com/reference/android/content/SharedPreferences.html" target="_blank">SharedPreferences</a> 实例。</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MainActivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FragmentActivity</span> {</span>
    ...
    <span class="hljs-javadoc">/**
     * A single Geofence object, defined by its center and radius.
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SimpleGeofence</span> {</span>
            <span class="hljs-comment">// Instance variables</span>
            <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> String mId;
            <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">double</span> mLatitude;
            <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">double</span> mLongitude;
            <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">float</span> mRadius;
            <span class="hljs-keyword">private</span> <span class="hljs-keyword">long</span> mExpirationDuration;
            <span class="hljs-keyword">private</span> <span class="hljs-keyword">int</span> mTransitionType;

        <span class="hljs-javadoc">/**
         *<span class="hljs-javadoctag"> @param</span> geofenceId The Geofence's request ID
         *<span class="hljs-javadoctag"> @param</span> latitude Latitude of the Geofence's center.
         *<span class="hljs-javadoctag"> @param</span> longitude Longitude of the Geofence's center.
         *<span class="hljs-javadoctag"> @param</span> radius Radius of the geofence circle.
         *<span class="hljs-javadoctag"> @param</span> expiration Geofence expiration duration
         *<span class="hljs-javadoctag"> @param</span> transition Type of Geofence transition.
         */</span>
        <span class="hljs-keyword">public</span> <span class="hljs-title">SimpleGeofence</span>(
                String geofenceId,
                <span class="hljs-keyword">double</span> latitude,
                <span class="hljs-keyword">double</span> longitude,
                <span class="hljs-keyword">float</span> radius,
                <span class="hljs-keyword">long</span> expiration,
                <span class="hljs-keyword">int</span> transition) {
            <span class="hljs-comment">// Set the instance fields from the constructor</span>
            <span class="hljs-keyword">this</span>.mId = geofenceId;
            <span class="hljs-keyword">this</span>.mLatitude = latitude;
            <span class="hljs-keyword">this</span>.mLongitude = longitude;
            <span class="hljs-keyword">this</span>.mRadius = radius;
            <span class="hljs-keyword">this</span>.mExpirationDuration = expiration;
            <span class="hljs-keyword">this</span>.mTransitionType = transition;
        }
        <span class="hljs-comment">// Instance field getters</span>
        <span class="hljs-keyword">public</span> String <span class="hljs-title">getId</span>() {
            <span class="hljs-keyword">return</span> mId;
        }
        <span class="hljs-keyword">public</span> <span class="hljs-keyword">double</span> <span class="hljs-title">getLatitude</span>() {
            <span class="hljs-keyword">return</span> mLatitude;
        }
        <span class="hljs-keyword">public</span> <span class="hljs-keyword">double</span> <span class="hljs-title">getLongitude</span>() {
            <span class="hljs-keyword">return</span> mLongitude;
        }
        <span class="hljs-keyword">public</span> <span class="hljs-keyword">float</span> <span class="hljs-title">getRadius</span>() {
            <span class="hljs-keyword">return</span> mRadius;
        }
        <span class="hljs-keyword">public</span> <span class="hljs-keyword">long</span> <span class="hljs-title">getExpirationDuration</span>() {
            <span class="hljs-keyword">return</span> mExpirationDuration;
        }
        <span class="hljs-keyword">public</span> <span class="hljs-keyword">int</span> <span class="hljs-title">getTransitionType</span>() {
            <span class="hljs-keyword">return</span> mTransitionType;
        }
        <span class="hljs-javadoc">/**
         * Creates a Location Services Geofence object from a
         * SimpleGeofence.
         *
         *<span class="hljs-javadoctag"> @return</span> A Geofence object
         */</span>
        <span class="hljs-keyword">public</span> Geofence <span class="hljs-title">toGeofence</span>() {
            <span class="hljs-comment">// Build a new Geofence object</span>
            <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> Geofence.Builder()
                    .setRequestId(getId())
                    .setTransitionTypes(mTransitionType)
                    .setCircularRegion(
                            getLatitude(), getLongitude(), getRadius())
                    .setExpirationDuration(mExpirationDuration)
                    .build();
        }
    }
    ...
    <span class="hljs-javadoc">/**
     * Storage for geofence values, implemented in SharedPreferences.
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SimpleGeofenceStore</span> {</span>
        <span class="hljs-comment">// Keys for flattened geofences stored in SharedPreferences</span>
        <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> String KEY_LATITUDE =
                <span class="hljs-string">"com.example.android.geofence.KEY_LATITUDE"</span>;
        <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> String KEY_LONGITUDE =
                <span class="hljs-string">"com.example.android.geofence.KEY_LONGITUDE"</span>;
        <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> String KEY_RADIUS =
                <span class="hljs-string">"com.example.android.geofence.KEY_RADIUS"</span>;
        <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> String KEY_EXPIRATION_DURATION =
                <span class="hljs-string">"com.example.android.geofence.KEY_EXPIRATION_DURATION"</span>;
        <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> String KEY_TRANSITION_TYPE =
                <span class="hljs-string">"com.example.android.geofence.KEY_TRANSITION_TYPE"</span>;
        <span class="hljs-comment">// The prefix for flattened geofence keys</span>
        <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> String KEY_PREFIX =
                <span class="hljs-string">"com.example.android.geofence.KEY"</span>;
        <span class="hljs-comment">/*
         * Invalid values, used to test geofence storage when
         * retrieving geofences
         */</span>
        <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">long</span> INVALID_LONG_VALUE = -<span class="hljs-number">999</span>l;
        <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">float</span> INVALID_FLOAT_VALUE = -<span class="hljs-number">999.0</span>f;
        <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">int</span> INVALID_INT_VALUE = -<span class="hljs-number">999</span>;
        <span class="hljs-comment">// The SharedPreferences object in which geofences are stored</span>
        <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> SharedPreferences mPrefs;
        <span class="hljs-comment">// The name of the SharedPreferences</span>
        <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> String SHARED_PREFERENCES =
                <span class="hljs-string">"SharedPreferences"</span>;
        <span class="hljs-comment">// Create the SharedPreferences storage with private access only</span>
        <span class="hljs-keyword">public</span> <span class="hljs-title">SimpleGeofenceStore</span>(Context context) {
            mPrefs =
                    context.getSharedPreferences(
                            SHARED_PREFERENCES,
                            Context.MODE_PRIVATE);
        }
        <span class="hljs-javadoc">/**
         * Returns a stored geofence by its id, or returns null
         * if it's not found.
         *
         *<span class="hljs-javadoctag"> @param</span> id The ID of a stored geofence
         *<span class="hljs-javadoctag"> @return</span> A geofence defined by its center and radius. See
         */</span>
        <span class="hljs-keyword">public</span> SimpleGeofence <span class="hljs-title">getGeofence</span>(String id) {
            <span class="hljs-comment">/*
             * Get the latitude for the geofence identified by id, or
             * INVALID_FLOAT_VALUE if it doesn't exist
             */</span>
            <span class="hljs-keyword">double</span> lat = mPrefs.getFloat(
                    getGeofenceFieldKey(id, KEY_LATITUDE),
                    INVALID_FLOAT_VALUE);
            <span class="hljs-comment">/*
             * Get the longitude for the geofence identified by id, or
             * INVALID_FLOAT_VALUE if it doesn't exist
             */</span>
            <span class="hljs-keyword">double</span> lng = mPrefs.getFloat(
                    getGeofenceFieldKey(id, KEY_LONGITUDE),
                    INVALID_FLOAT_VALUE);
            <span class="hljs-comment">/*
             * Get the radius for the geofence identified by id, or
             * INVALID_FLOAT_VALUE if it doesn't exist
             */</span>
            <span class="hljs-keyword">float</span> radius = mPrefs.getFloat(
                    getGeofenceFieldKey(id, KEY_RADIUS),
                    INVALID_FLOAT_VALUE);
            <span class="hljs-comment">/*
             * Get the expiration duration for the geofence identified
             * by id, or INVALID_LONG_VALUE if it doesn't exist
             */</span>
            <span class="hljs-keyword">long</span> expirationDuration = mPrefs.getLong(
                    getGeofenceFieldKey(id, KEY_EXPIRATION_DURATION),
                    INVALID_LONG_VALUE);
            <span class="hljs-comment">/*
             * Get the transition type for the geofence identified by
             * id, or INVALID_INT_VALUE if it doesn't exist
             */</span>
            <span class="hljs-keyword">int</span> transitionType = mPrefs.getInt(
                    getGeofenceFieldKey(id, KEY_TRANSITION_TYPE),
                    INVALID_INT_VALUE);
            <span class="hljs-comment">// If none of the values is incorrect, return the object</span>
            <span class="hljs-keyword">if</span> (
                lat != GeofenceUtils.INVALID_FLOAT_VALUE &amp;&amp;
                lng != GeofenceUtils.INVALID_FLOAT_VALUE &amp;&amp;
                radius != GeofenceUtils.INVALID_FLOAT_VALUE &amp;&amp;
                expirationDuration !=
                        GeofenceUtils.INVALID_LONG_VALUE &amp;&amp;
                transitionType != GeofenceUtils.INVALID_INT_VALUE) {

                <span class="hljs-comment">// Return a true Geofence object</span>
                <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> SimpleGeofence(
                        id, lat, lng, radius, expirationDuration,
                        transitionType);
            <span class="hljs-comment">// Otherwise, return null.</span>
            } <span class="hljs-keyword">else</span> {
                <span class="hljs-keyword">return</span> <span class="hljs-keyword">null</span>;
            }
        }
        <span class="hljs-javadoc">/**
         * Save a geofence.
         *<span class="hljs-javadoctag"> @param</span> geofence The SimpleGeofence containing the
         * values you want to save in SharedPreferences
         */</span>
        <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setGeofence</span>(String id, SimpleGeofence geofence) {
            <span class="hljs-comment">/*
             * Get a SharedPreferences editor instance. Among other
             * things, SharedPreferences ensures that updates are atomic
             * and non-concurrent
             */</span>
            Editor editor = mPrefs.edit();
            <span class="hljs-comment">// Write the Geofence values to SharedPreferences</span>
            editor.putFloat(
                    getGeofenceFieldKey(id, KEY_LATITUDE),
                    (<span class="hljs-keyword">float</span>) geofence.getLatitude());
            editor.putFloat(
                    getGeofenceFieldKey(id, KEY_LONGITUDE),
                    (<span class="hljs-keyword">float</span>) geofence.getLongitude());
            editor.putFloat(
                    getGeofenceFieldKey(id, KEY_RADIUS),
                    geofence.getRadius());
            editor.putLong(
                    getGeofenceFieldKey(id, KEY_EXPIRATION_DURATION),
                    geofence.getExpirationDuration());
            editor.putInt(
                    getGeofenceFieldKey(id, KEY_TRANSITION_TYPE),
                    geofence.getTransitionType());
            <span class="hljs-comment">// Commit the changes</span>
            editor.commit();
        }
        <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">clearGeofence</span>(String id) {
            <span class="hljs-comment">/*
             * Remove a flattened geofence object from storage by
             * removing all of its keys
             */</span>
            Editor editor = mPrefs.edit();
            editor.remove(getGeofenceFieldKey(id, KEY_LATITUDE));
            editor.remove(getGeofenceFieldKey(id, KEY_LONGITUDE));
            editor.remove(getGeofenceFieldKey(id, KEY_RADIUS));
            editor.remove(getGeofenceFieldKey(id,
                    KEY_EXPIRATION_DURATION));
            editor.remove(getGeofenceFieldKey(id, KEY_TRANSITION_TYPE));
            editor.commit();
        }
        <span class="hljs-javadoc">/**
         * Given a Geofence object's ID and the name of a field
         * (for example, KEY_LATITUDE), return the key name of the
         * object's values in SharedPreferences.
         *
         *<span class="hljs-javadoctag"> @param</span> id The ID of a Geofence object
         *<span class="hljs-javadoctag"> @param</span> fieldName The field represented by the key
         *<span class="hljs-javadoctag"> @return</span> The full key name of a value in SharedPreferences
         */</span>
        <span class="hljs-keyword">private</span> String <span class="hljs-title">getGeofenceFieldKey</span>(String id,
                String fieldName) {
            <span class="hljs-keyword">return</span> KEY_PREFIX + <span class="hljs-string">"_"</span> + id + <span class="hljs-string">"_"</span> + fieldName;
        }
    }
    ...
}
</code></pre>
<h3 id="-">创建地理围栏对象</h3>
<p>下面的代码片段使用<code>SimpleGeofence</code>和<code>SimpleGeofenceStore</code>类从用户界面上获取地理围栏数据，然后将这些数据保存到<code>SimpleGeofence</code>对象里面，接着把这些<code>SimpleGeofence</code>对象保存到一个<code>SimpleGeofenceStore</code>里面，然后就可以创建 <a href="http://developer.android.com/reference/com/google/android/gms/location/Geofence.html" target="_blank">Geofence</a>对象了:</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MainActivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FragmentActivity</span> {</span>
    ...
    <span class="hljs-comment">/*
     * Use to set an expiration time for a geofence. After this amount
     * of time Location Services will stop tracking the geofence.
     */</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">long</span> SECONDS_PER_HOUR = <span class="hljs-number">60</span>;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">long</span> MILLISECONDS_PER_SECOND = <span class="hljs-number">1000</span>;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">long</span> GEOFENCE_EXPIRATION_IN_HOURS = <span class="hljs-number">12</span>;
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">long</span> GEOFENCE_EXPIRATION_TIME =
            GEOFENCE_EXPIRATION_IN_HOURS *
            SECONDS_PER_HOUR *
            MILLISECONDS_PER_SECOND;
    ...
    <span class="hljs-comment">/*
     * Handles to UI views containing geofence data
     */</span>
    <span class="hljs-comment">// Handle to geofence 1 latitude in the UI</span>
    <span class="hljs-keyword">private</span> EditText mLatitude1;
    <span class="hljs-comment">// Handle to geofence 1 longitude in the UI</span>
    <span class="hljs-keyword">private</span> EditText mLongitude1;
    <span class="hljs-comment">// Handle to geofence 1 radius in the UI</span>
    <span class="hljs-keyword">private</span> EditText mRadius1;
    <span class="hljs-comment">// Handle to geofence 2 latitude in the UI</span>
    <span class="hljs-keyword">private</span> EditText mLatitude2;
    <span class="hljs-comment">// Handle to geofence 2 longitude in the UI</span>
    <span class="hljs-keyword">private</span> EditText mLongitude2;
    <span class="hljs-comment">// Handle to geofence 2 radius in the UI</span>
    <span class="hljs-keyword">private</span> EditText mRadius2;
    <span class="hljs-comment">/*
     * Internal geofence objects for geofence 1 and 2
     */</span>
    <span class="hljs-keyword">private</span> SimpleGeofence mUIGeofence1;
    <span class="hljs-keyword">private</span> SimpleGeofence mUIGeofence2;
    ...
    <span class="hljs-comment">// Internal List of Geofence objects</span>
    List&lt;Geofence&gt; mGeofenceList;
    <span class="hljs-comment">// Persistent storage for geofences</span>
    <span class="hljs-keyword">private</span> SimpleGeofenceStore mGeofenceStorage;
    ...
    <span class="hljs-annotation">@Override</span>
    <span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onCreate</span>(Bundle savedInstanceState) {
        <span class="hljs-keyword">super</span>.onCreate(savedInstanceState);
        ...
        <span class="hljs-comment">// Instantiate a new geofence storage area</span>
        mGeofenceStorage = <span class="hljs-keyword">new</span> SimpleGeofenceStore(<span class="hljs-keyword">this</span>);

        <span class="hljs-comment">// Instantiate the current List of geofences</span>
        mCurrentGeofences = <span class="hljs-keyword">new</span> ArrayList&lt;Geofence&gt;();
    }
    ...
    <span class="hljs-javadoc">/**
     * Get the geofence parameters for each geofence from the UI
     * and add them to a List.
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">createGeofences</span>() {
        <span class="hljs-comment">/*
         * Create an internal object to store the data. Set its
         * ID to "1". This is a "flattened" object that contains
         * a set of strings
         */</span>
        mUIGeofence1 = <span class="hljs-keyword">new</span> SimpleGeofence(
                <span class="hljs-string">"1"</span>,
                Double.valueOf(mLatitude1.getText().toString()),
                Double.valueOf(mLongitude1.getText().toString()),
                Float.valueOf(mRadius1.getText().toString()),
                GEOFENCE_EXPIRATION_TIME,
                <span class="hljs-comment">// This geofence records only entry transitions</span>
                Geofence.GEOFENCE_TRANSITION_ENTER);
        <span class="hljs-comment">// Store this flat version</span>
        mGeofenceStorage.setGeofence(<span class="hljs-string">"1"</span>, mUIGeofence1);
        <span class="hljs-comment">// Create another internal object. Set its ID to "2"</span>
        mUIGeofence2 = <span class="hljs-keyword">new</span> SimpleGeofence(
                <span class="hljs-string">"2"</span>,
                Double.valueOf(mLatitude2.getText().toString()),
                Double.valueOf(mLongitude2.getText().toString()),
                Float.valueOf(mRadius2.getText().toString()),
                GEOFENCE_EXPIRATION_TIME,
                <span class="hljs-comment">// This geofence records both entry and exit transitions</span>
                Geofence.GEOFENCE_TRANSITION_ENTER |
                Geofence.GEOFENCE_TRANSITION_EXIT);
        <span class="hljs-comment">// Store this flat version</span>
        mGeofenceStorage.setGeofence(<span class="hljs-number">2</span>, mUIGeofence2);
        mGeofenceList.add(mUIGeofence1.toGeofence());
        mGeofenceList.add(mUIGeofence2.toGeofence());
    }
    ...
}
</code></pre>
<p>除了这些你要监视的<a href="http://developer.android.com/reference/com/google/android/gms/location/Geofence.html" target="_blank">Geofence</a>列表之外，你还需要为Location Services添加<a href="http://developer.android.com/reference/android/content/Intent.html" target="_blank">Intent</a>，这个Intent在你的应用探测到地理围栏触发事件时会将这个事件发送给你的应用。</p>
<h3 id="-intent">为地理围栏触发事件定义Intent</h3>
<p>从Location Services发送来的Intent能够触发各种应用内的动作，但是不能用它来打开一个Activity或者Fragment，因为应用内的组件只能在响应用户动作时才能可见。大多数情况下，处理这一类的Intent最好使用<a href="http://developer.android.com/reference/android/app/IntentService.html" target="_blank">IntentService</a>。一个<a href="http://developer.android.com/reference/android/app/IntentService.html" target="_blank">IntentService</a>可以推送一个通知，可以进行长时的后台作业，可以将intent发送给其他的services，还可以广播intent。下面的代码展示了如何定义一个<a href="http://developer.android.com/reference/android/app/PendingIntent.html" target="_blank">PendingIntent</a>来启动一个IntentService:</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MainActivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FragmentActivity</span> {</span>
    ...
    <span class="hljs-comment">/*
     * Create a PendingIntent that triggers an IntentService in your
     * app when a geofence transition occurs.
     */</span>
    <span class="hljs-keyword">private</span> PendingIntent <span class="hljs-title">getTransitionPendingIntent</span>() {
        <span class="hljs-comment">// Create an explicit Intent</span>
        Intent intent = <span class="hljs-keyword">new</span> Intent(<span class="hljs-keyword">this</span>,
                ReceiveTransitionsIntentService.class);
        <span class="hljs-comment">/*
         * Return the PendingIntent
         */</span>
        <span class="hljs-keyword">return</span> PendingIntent.getService(
                <span class="hljs-keyword">this</span>,
                <span class="hljs-number">0</span>,
                intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
    }
    ...
}
</code></pre>
<p>现在你已经拥有了所有发送监视地理围栏请求给Location Services的代码了。</p>
<h3 id="-">发送监视请求</h3>
<p>发送监视请求需要两个异步操作。第一个操作就是为这个请求获取一个location client，第二个操作就是使用这个client来生成请求。这两个操作里面，Location Services都会在操作结束的时候调用一个回调函数。处理这些操作最好的方法就是将这些方法调用连接起来。下面的代码展示了如何建立一个Activity，接着定义回调方法，然后以合适的顺序调用他们。
首先，让Activity实现必要的回调接口。需要添加以下接口：
<a href="http://developer.android.com/reference/com/google/android/gms/common/GooglePlayServicesClient.ConnectionCallbacks.html" target="_blank">ConnectionCallbacks</a></p>
<ul>
<li>设置当location client已连接或者断开连接时Location Services调用的方法。</li>
</ul>
<p><a href="http://developer.android.com/reference/com/google/android/gms/common/GooglePlayServicesClient.OnConnectionFailedListener.html" target="_blank">OnConnectionFailedListener</a></p>
<ul>
<li>设置当Location Services连接location client出错时Location Services调用的方法。</li>
</ul>
<p><a href="http://developer.android.com/reference/com/google/android/gms/location/LocationClient.OnAddGeofencesResultListener.html" target="_blank">OnAddGeofencesResultListener</a></p>
<ul>
<li>设置当Location Services已经添加地理围栏的时候Location Services调用的方法。</li>
</ul>
<p>例如：</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MainActivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FragmentActivity</span> <span class="hljs-keyword">implements</span>
        <span class="hljs-title">ConnectionCallbacks</span>,
        <span class="hljs-title">OnConnectionFailedListener</span>,
        <span class="hljs-title">OnAddGeofencesResultListener</span> {</span>
    ...
}
</code></pre>
<h3 id="-">开始请求进程</h3>
<p>接下啦，在连接Location Services的时候定义一个启动请求进程的方法。记得将这个请求设置为全局变量，这样就可以让你使用回调方法<a href="http://developer.android.com/reference/com/google/android/gms/common/GooglePlayServicesClient.ConnectionCallbacks.html#onConnected(android.os.Bundle" target="_blank">ConnectionCallbacks.onConnected()</a>)来添加地理围栏，或者移除地理围栏。</p>
<p>为了防止当你的应用在第一个请求还没结束就开始第二个请求的时候不出现竞争状况，你可以定义一个boolean标志位来记录当前请求的状态：</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MainActivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FragmentActivity</span> <span class="hljs-keyword">implements</span>
        <span class="hljs-title">ConnectionCallbacks</span>,
        <span class="hljs-title">OnConnectionFailedListener</span>,
        <span class="hljs-title">OnAddGeofencesResultListener</span> {</span>
    ...
    <span class="hljs-comment">// Holds the location client</span>
    <span class="hljs-keyword">private</span> LocationClient mLocationClient;
    <span class="hljs-comment">// Stores the PendingIntent used to request geofence monitoring</span>
    <span class="hljs-keyword">private</span> PendingIntent mGeofenceRequestIntent;
    <span class="hljs-comment">// Defines the allowable request types.</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">enum</span> REQUEST_TYPE = {ADD}
    <span class="hljs-keyword">private</span> REQUEST_TYPE mRequestType;
    <span class="hljs-comment">// Flag that indicates if a request is underway.</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">boolean</span> mInProgress;
    ...
    <span class="hljs-annotation">@Override</span>
    <span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onCreate</span>(Bundle savedInstanceState) {
        ...
        <span class="hljs-comment">// Start with the request flag set to false</span>
        mInProgress = <span class="hljs-keyword">false</span>;
        ...
    }
    ...
    <span class="hljs-javadoc">/**
     * Start a request for geofence monitoring by calling
     * LocationClient.connect().
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">addGeofences</span>() {
        <span class="hljs-comment">// Start a request to add geofences</span>
        mRequestType = ADD;
        <span class="hljs-comment">/*
         * Test for Google Play services after setting the request type.
         * If Google Play services isn't present, the proper request
         * can be restarted.
         */</span>
        <span class="hljs-keyword">if</span> (!servicesConnected()) {
            <span class="hljs-keyword">return</span>;
        }
        <span class="hljs-comment">/*
         * Create a new location client object. Since the current
         * activity class implements ConnectionCallbacks and
         * OnConnectionFailedListener, pass the current activity object
         * as the listener for both parameters
         */</span>
        mLocationClient = <span class="hljs-keyword">new</span> LocationClient(<span class="hljs-keyword">this</span>, <span class="hljs-keyword">this</span>, <span class="hljs-keyword">this</span>)
        <span class="hljs-comment">// If a request is not already underway</span>
        <span class="hljs-keyword">if</span> (!mInProgress) {
            <span class="hljs-comment">// Indicate that a request is underway</span>
            mInProgress = <span class="hljs-keyword">true</span>;
            <span class="hljs-comment">// Request a connection from the client to Location Services</span>
            mLocationClient.connect();
        } <span class="hljs-keyword">else</span> {
            <span class="hljs-comment">/*
             * A request is already underway. You can handle
             * this situation by disconnecting the client,
             * re-setting the flag, and then re-trying the
             * request.
             */</span>
        }
    }
    ...
}
</code></pre>
<h3 id="-">发送添加地理围栏的请求</h3>
<p>在你对回调方法<a href="http://developer.android.com/reference/com/google/android/gms/common/GooglePlayServicesClient.ConnectionCallbacks.html#onConnected(android.os.Bundle" target="_blank">ConnectionCallbacks.onConnected()</a>)的实现里面，调用 <a href="http://developer.android.com/reference/com/google/android/gms/location/LocationClient.html#addGeofences(java.util.List&lt;com.google.android.gms.location.Geofence&gt;, android.app.PendingIntent, com.google.android.gms.location.LocationClient.OnAddGeofencesResultListener" target="_blank">LocationClient.addGeofences()</a>)。注意如果连接失败，<a href="http://developer.android.com/reference/com/google/android/gms/common/GooglePlayServicesClient.ConnectionCallbacks.html#onConnected(android.os.Bundle" target="_blank">onConnected()</a>)方法不会被调用，这个请求也会停止。</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MainActivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FragmentActivity</span> <span class="hljs-keyword">implements</span>
        <span class="hljs-title">ConnectionCallbacks</span>,
        <span class="hljs-title">OnConnectionFailedListener</span>,
        <span class="hljs-title">OnAddGeofencesResultListener</span> {</span>
    ...
    <span class="hljs-comment">/*
     * Provide the implementation of ConnectionCallbacks.onConnected()
     * Once the connection is available, send a request to add the
     * Geofences
     */</span>
    <span class="hljs-annotation">@Override</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onConnected</span>(Bundle dataBundle) {
        ...
        <span class="hljs-keyword">switch</span> (mRequestType) {
            <span class="hljs-keyword">case</span> ADD :
                <span class="hljs-comment">// Get the PendingIntent for the request</span>
                mTransitionPendingIntent =
                        getTransitionPendingIntent();
                <span class="hljs-comment">// Send a request to add the current geofences</span>
                mLocationClient.addGeofences(
                        mCurrentGeofences, pendingIntent, <span class="hljs-keyword">this</span>);
            ...
        }
    }
    ...
}
</code></pre>
<p>注意<a href="http://developer.android.com/reference/com/google/android/gms/location/LocationClient.html#addGeofences(java.util.List&lt;com.google.android.gms.location.Geofence&gt;, android.app.PendingIntent, com.google.android.gms.location.LocationClient.OnAddGeofencesResultListener" target="_blank">addGeofences()</a>)方法会直接返回，但是请求的状态却不是直接返回的，只有等到Location Services调用 <a href="http://developer.android.com/reference/com/google/android/gms/location/LocationClient.OnAddGeofencesResultListener.html#onAddGeofencesResult(int, java.lang.String[]" target="_blank">onAddGeofencesResult()</a>方法。一旦这个方法被调用，你就能知道这个请求是否成功。</p>
<h3 id="-location-services-">通过Location Services检测请求返回的结果</h3>
<p>当 Location Services 你对回调函数<a href="http://developer.android.com/reference/com/google/android/gms/location/LocationClient.OnAddGeofencesResultListener.html#onAddGeofencesResult(int, java.lang.String[]" target="_blank">onAddGeofencesResult()</a>的实现的时候，说明请求已经结束，你可以检测最终的结果状态码。如果请求成功，那么你轻轻的地理围栏是激活的，如果没有成功，那么你请求的地理围栏没有激活。如果没成功，你需要重试或者报告错误。例如：</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MainActivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FragmentActivity</span> <span class="hljs-keyword">implements</span>
        <span class="hljs-title">ConnectionCallbacks</span>,
        <span class="hljs-title">OnConnectionFailedListener</span>,
        <span class="hljs-title">OnAddGeofencesResultListener</span> {</span>
        ...
    <span class="hljs-comment">/*
     * Provide the implementation of
     * OnAddGeofencesResultListener.onAddGeofencesResult.
     * Handle the result of adding the geofences
     *
     */</span>
    <span class="hljs-annotation">@Override</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onAddGeofencesResult</span>(
            <span class="hljs-keyword">int</span> statusCode, String[] geofenceRequestIds) {
        <span class="hljs-comment">// If adding the geofences was successful</span>
        <span class="hljs-keyword">if</span> (LocationStatusCodes.SUCCESS == statusCode) {
            <span class="hljs-comment">/*
             * Handle successful addition of geofences here.
             * You can send out a broadcast intent or update the UI.
             * geofences into the Intent's extended data.
             */</span>
        } <span class="hljs-keyword">else</span> {
        <span class="hljs-comment">// If adding the geofences failed</span>
            <span class="hljs-comment">/*
             * Report errors here.
             * You can log the error using Log.e() or update
             * the UI.
             */</span>
        }
        <span class="hljs-comment">// Turn off the in progress flag and disconnect the client</span>
        mInProgress = <span class="hljs-keyword">false</span>;
        mLocationClient.disconnect();
    }
    ...
}
</code></pre>
<h3 id="-">处理断开连接</h3>
<p>某些情况下，Location Services可能会在你调用disconnect()方法之前断开连接。为了处理这种情况，你需要实现onDisconnected()方法。在这个方法里面，设置请求状态标志位来表示这个请求已经不处于进程中，然后删除这个client：</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MainActivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FragmentActivity</span> <span class="hljs-keyword">implements</span>
        <span class="hljs-title">ConnectionCallbacks</span>,
        <span class="hljs-title">OnConnectionFailedListener</span>,
        <span class="hljs-title">OnAddGeofencesResultListener</span> {</span>
    ...
    <span class="hljs-comment">/*
     * Implement ConnectionCallbacks.onDisconnected()
     * Called by Location Services once the location client is
     * disconnected.
     */</span>
    <span class="hljs-annotation">@Override</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onDisconnected</span>() {
        <span class="hljs-comment">// Turn off the request flag</span>
        mInProgress = <span class="hljs-keyword">false</span>;
        <span class="hljs-comment">// Destroy the current location client</span>
        mLocationClient = <span class="hljs-keyword">null</span>;
    }
    ...
}
</code></pre>
<h3 id="-">处理连接错误</h3>
<p>在处理正常的回调函数之外，你还得提供一个回调函数来处理连接出现错误的情况。这个回调函数重用了前面在检查Google Play service的时候用到的DialogFragment类。它还可以重用之前在onActivityResult()方法里用来接收当用户和错误对话框交互时产生的结果用到的代码。下面的代码展示了如何实现回调函数：</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MainActivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FragmentActivity</span> <span class="hljs-keyword">implements</span>
        <span class="hljs-title">ConnectionCallbacks</span>,
        <span class="hljs-title">OnConnectionFailedListener</span>,
        <span class="hljs-title">OnAddGeofencesResultListener</span> {</span>
    ...
    <span class="hljs-comment">// Implementation of OnConnectionFailedListener.onConnectionFailed</span>
    <span class="hljs-annotation">@Override</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onConnectionFailed</span>(ConnectionResult connectionResult) {
        <span class="hljs-comment">// Turn off the request flag</span>
        mInProgress = <span class="hljs-keyword">false</span>;
        <span class="hljs-comment">/*
         * If the error has a resolution, start a Google Play services
         * activity to resolve it.
         */</span>
        <span class="hljs-keyword">if</span> (connectionResult.hasResolution()) {
            <span class="hljs-keyword">try</span> {
                connectionResult.startResolutionForResult(
                        <span class="hljs-keyword">this</span>,
                        CONNECTION_FAILURE_RESOLUTION_REQUEST);
            } <span class="hljs-keyword">catch</span> (SendIntentException e) {
                <span class="hljs-comment">// Log the error</span>
                e.printStackTrace();
            }
        <span class="hljs-comment">// If no resolution is available, display an error dialog</span>
        } <span class="hljs-keyword">else</span> {
            <span class="hljs-comment">// Get the error code</span>
            <span class="hljs-keyword">int</span> errorCode = connectionResult.getErrorCode();
            <span class="hljs-comment">// Get the error dialog from Google Play services</span>
            Dialog errorDialog = GooglePlayServicesUtil.getErrorDialog(
                    errorCode,
                    <span class="hljs-keyword">this</span>,
                    CONNECTION_FAILURE_RESOLUTION_REQUEST);
            <span class="hljs-comment">// If Google Play services can provide an error dialog</span>
            <span class="hljs-keyword">if</span> (errorDialog != <span class="hljs-keyword">null</span>) {
                <span class="hljs-comment">// Create a new DialogFragment for the error dialog</span>
                ErrorDialogFragment errorFragment =
                        <span class="hljs-keyword">new</span> ErrorDialogFragment();
                <span class="hljs-comment">// Set the dialog in the DialogFragment</span>
                errorFragment.setDialog(errorDialog);
                <span class="hljs-comment">// Show the error dialog in the DialogFragment</span>
                errorFragment.show(
                        getSupportFragmentManager(),
                        <span class="hljs-string">"Geofence Detection"</span>);
            }
        }
    }
    ...
}
</code></pre>
<h2 id="-">处理地理围栏触发事件</h2>
<p>当Location Services探测到用户进入或者退出一个地理围栏，它会发送一个Intent，这个Intent就是</p>
<h3 id="-intentservice">定义一个IntentService</h3>
<p>下面的代码展示了如何定义一个当一个地理围栏触发事件出现的时候发送通知。当用户点击这个通知，这个应用的主界面出现：</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ReceiveTransitionsIntentService</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">IntentService</span> {</span>
    ...
    <span class="hljs-javadoc">/**
     * Sets an identifier for the service
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-title">ReceiveTransitionsIntentService</span>() {
        <span class="hljs-keyword">super</span>(<span class="hljs-string">"ReceiveTransitionsIntentService"</span>);
    }
    <span class="hljs-javadoc">/**
     * Handles incoming intents
     *@param intent The Intent sent by Location Services. This
     * Intent is provided
     * to Location Services (inside a PendingIntent) when you call
     * addGeofences()
     */</span>
    <span class="hljs-annotation">@Override</span>
    <span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onHandleIntent</span>(Intent intent) {
        <span class="hljs-comment">// First check for errors</span>
        <span class="hljs-keyword">if</span> (LocationClient.hasError(intent)) {
            <span class="hljs-comment">// Get the error code with a static method</span>
            <span class="hljs-keyword">int</span> errorCode = LocationClient.getErrorCode(intent);
            <span class="hljs-comment">// Log the error</span>
            Log.e(<span class="hljs-string">"ReceiveTransitionsIntentService"</span>,
                    <span class="hljs-string">"Location Services error: "</span> +
                    Integer.toString(errorCode));
            <span class="hljs-comment">/*
             * You can also send the error code to an Activity or
             * Fragment with a broadcast Intent
             */</span>
        <span class="hljs-comment">/*
         * If there's no error, get the transition type and the IDs
         * of the geofence or geofences that triggered the transition
         */</span>
        } <span class="hljs-keyword">else</span> {
            <span class="hljs-comment">// Get the type of transition (entry or exit)</span>
            <span class="hljs-keyword">int</span> transitionType =
                    LocationClient.getGeofenceTransition(intent);
            <span class="hljs-comment">// Test that a valid transition was reported</span>
            <span class="hljs-keyword">if</span> (
                (transitionType == Geofence.GEOFENCE_TRANSITION_ENTER)
                 ||
                (transitionType == Geofence.GEOFENCE_TRANSITION_EXIT)
               ) {
                List &lt;Geofence&gt; triggerList =
                        getTriggeringGeofences(intent);

                String[] triggerIds = <span class="hljs-keyword">new</span> String[geofenceList.size()];

                <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i &lt; triggerIds.length; i++) {
                    <span class="hljs-comment">// Store the Id of each geofence</span>
                    triggerIds[i] = triggerList.get(i).getRequestId();
                }
                <span class="hljs-comment">/*
                 * At this point, you can store the IDs for further use
                 * display them, or display the details associated with
                 * them.
                 */</span>
            }
        <span class="hljs-comment">// An invalid transition was reported</span>
        } <span class="hljs-keyword">else</span> {
            Log.e(<span class="hljs-string">"ReceiveTransitionsIntentService"</span>,
                    <span class="hljs-string">"Geofence transition error: "</span> +
                    Integer.toString()transitionType));
        }
    }
    ...
}
</code></pre>
<h3 id="-manifest-intentservice">在manifest里面设置IntentService</h3>
<p>为了在系统里面申明这个IntentService，在manifest里面添加一个<code>&lt;service&gt;</code> 元素即可。例如：</p>
<pre><code class="lang-java">&lt;service
    android:name="com.example.android.location.ReceiveTransitionsIntentService"
    android:label="@string/app_name"
    android:exported="false"&gt;
&lt;/service&gt;
</code></pre>
<p>注意你不必为这个service设置intent filters，因为它只接收特定的intent。这些地理围栏触发事件的intent是如何被创建的，请参看<a href="geofencing.html#requestmonitoring">发送监视请求</a>这一课。</p>
<h2 id="-">停止地理围栏监视</h2>
<p>要停止地理围栏监视，你要移除这些地理围栏。你可以移除特定的某个地理围栏集合或者移除与某个<a href="http://developer.android.com/reference/android/app/PendingIntent.html" target="_blank">PendingIntent</a>相关所有的地理围栏。这个过程与添加地理围栏类似。第一个操作就是获取一个移除请求的location client，然后使用这个client来生成请求。</p>
<p>Location Services在它完成移除地理围栏这个过程的时候调用的回调函数定义在<a href="http://developer.android.com/reference/com/google/android/gms/location/LocationClient.OnRemoveGeofencesResultListener.html" target="_blank">LocationClient.OnRemoveGeofencesResultListener</a>这个接口里面。在你的类里面申明这个接口，然后为它的两个方法添加定义：</p>
<p><a href="http://developer.android.com/reference/com/google/android/gms/location/LocationClient.OnRemoveGeofencesResultListener.html#onRemoveGeofencesByPendingIntentResult(int, android.app.PendingIntent" target="_blank">onRemoveGeofencesByPendingIntentResult()</a></p>
<ul>
<li>这个回调函数是Location Services完成移除所有地理围栏的请求时调用的，它是由 <a href="http://developer.android.com/reference/com/google/android/gms/location/LocationClient.html#removeGeofences(android.app.PendingIntent, com.google.android.gms.location.LocationClient.OnRemoveGeofencesResultListener" target="_blank">removeGeofences(PendingIntent, LocationClient.OnRemoveGeofencesResultListener)</a>)方法生成的。</li>
</ul>
<p><a href="http://developer.android.com/reference/com/google/android/gms/location/LocationClient.OnRemoveGeofencesResultListener.html#onRemoveGeofencesByRequestIdsResult(int, java.lang.String[]" target="_blank">onRemoveGeofencesByRequestIdsResult(List<String>, LocationClient.OnRemoveGeofencesResultListener)</a>)</p>
<ul>
<li>这个回调函数是Location Services完成移除特定地理围栏ID集合的地理围栏的请求时调用的，它由 <a href="http://developer.android.com/reference/com/google/android/gms/location/LocationClient.html#removeGeofences(java.util.List&lt;java.lang.String&gt;, com.google.android.gms.location.LocationClient.OnRemoveGeofencesResultListener" target="_blank">removeGeofences(List<String>, LocationClient.OnRemoveGeofencesResultListener)</a>方法生成的。</li>
</ul>
<p>这些实现的代码将在下一个代码区域出现。</p>
<h3 id="-">移除所有的地理围栏</h3>
<p>因为移除地理围栏使用了添加地理围栏时的一些方法，你只需要添加另外几种请求类型即可：</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MainActivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FragmentActivity</span> <span class="hljs-keyword">implements</span>
        <span class="hljs-title">ConnectionCallbacks</span>,
        <span class="hljs-title">OnConnectionFailedListener</span>,
        <span class="hljs-title">OnAddGeofencesResultListener</span> {</span>
    ...
    <span class="hljs-comment">// Enum type for controlling the type of removal requested</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">enum</span> REQUEST_TYPE = {ADD, REMOVE_INTENT}
    ...
}
</code></pre>
<p>在连接上Location Services的时候启动移除的请求。如果连接失败，那么<a href="http://developer.android.com/reference/com/google/android/gms/common/GooglePlayServicesClient.ConnectionCallbacks.html#onConnected(android.os.Bundle" target="_blank">onConnected()</a>方法就不会被调用，请求也就停止了。下面的代码就展示了如何启动这个请求：</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MainActivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FragmentActivity</span> <span class="hljs-keyword">implements</span>
        <span class="hljs-title">ConnectionCallbacks</span>,
        <span class="hljs-title">OnConnectionFailedListener</span>,
        <span class="hljs-title">OnAddGeofencesResultListener</span> {</span>
    ...
    <span class="hljs-javadoc">/**
     * Start a request to remove geofences by calling
     * LocationClient.connect()
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">removeGeofences</span>(PendingIntent requestIntent) {
        <span class="hljs-comment">// Record the type of removal request</span>
        mRequestType = REMOVE_INTENT;
        <span class="hljs-comment">/*
         * Test for Google Play services after setting the request type.
         * If Google Play services isn't present, the request can be
         * restarted.
         */</span>
        <span class="hljs-keyword">if</span> (!servicesConnected()) {
            <span class="hljs-keyword">return</span>;
        }
        <span class="hljs-comment">// Store the PendingIntent</span>
        mGeofenceRequestIntent = requestIntent;
        <span class="hljs-comment">/*
         * Create a new location client object. Since the current
         * activity class implements ConnectionCallbacks and
         * OnConnectionFailedListener, pass the current activity object
         * as the listener for both parameters
         */</span>
        mLocationClient = <span class="hljs-keyword">new</span> LocationClient(<span class="hljs-keyword">this</span>, <span class="hljs-keyword">this</span>, <span class="hljs-keyword">this</span>);
        <span class="hljs-comment">// If a request is not already underway</span>
        <span class="hljs-keyword">if</span> (!mInProgress) {
            <span class="hljs-comment">// Indicate that a request is underway</span>
            mInProgress = <span class="hljs-keyword">true</span>;
            <span class="hljs-comment">// Request a connection from the client to Location Services</span>
            mLocationClient.connect();
        } <span class="hljs-keyword">else</span> {
            <span class="hljs-comment">/*
             * A request is already underway. You can handle
             * this situation by disconnecting the client,
             * re-setting the flag, and then re-trying the
             * request.
             */</span>
        }
    }
    ...
}
</code></pre>
<p>当Location Services调用这个函数的时候就表明连接已经打开，可以进行移除所有地理围栏的请求了。在这个请求完成之后就可以断开连接了。例如：</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MainActivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FragmentActivity</span> <span class="hljs-keyword">implements</span>
        <span class="hljs-title">ConnectionCallbacks</span>,
        <span class="hljs-title">OnConnectionFailedListener</span>,
        <span class="hljs-title">OnAddGeofencesResultListener</span> {</span>
    ...
    <span class="hljs-javadoc">/**
     * Once the connection is available, send a request to remove the
     * Geofences. The method signature used depends on which type of
     * remove request was originally received.
     */</span>
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onConnected</span>(Bundle dataBundle) {
        <span class="hljs-comment">/*
         * Choose what to do based on the request type set in
         * removeGeofences
         */</span>
        <span class="hljs-keyword">switch</span> (mRequestType) {
            ...
            <span class="hljs-keyword">case</span> REMOVE_INTENT :
                mLocationClient.removeGeofences(
                        mGeofenceRequestIntent, <span class="hljs-keyword">this</span>);
                <span class="hljs-keyword">break</span>;
            ...
        }
    }
    ...
}
</code></pre>
<p>对<a href="http://developer.android.com/reference/com/google/android/gms/location/LocationClient.html#removeGeofences(android.app.PendingIntent, com.google.android.gms.location.LocationClient.OnRemoveGeofencesResultListener" target="_blank">removeGeofences(PendingIntent, LocationClient.OnRemoveGeofencesResultListener)</a>)会直接返回，而移除地理围栏的请求的结果要等到Location Services 调用onRemoveGeofencesByPendingIntentResult()方法才会返回。下面的代码展示了如何定义这个方法：</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MainActivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FragmentActivity</span> <span class="hljs-keyword">implements</span>
        <span class="hljs-title">ConnectionCallbacks</span>,
        <span class="hljs-title">OnConnectionFailedListener</span>,
        <span class="hljs-title">OnAddGeofencesResultListener</span> {</span>
    ...
    <span class="hljs-javadoc">/**
     * When the request to remove geofences by PendingIntent returns,
     * handle the result.
     *
     *@param statusCode the code returned by Location Services
     *@param requestIntent The Intent used to request the removal.
     */</span>
    <span class="hljs-annotation">@Override</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onRemoveGeofencesByPendingIntentResult</span>(<span class="hljs-keyword">int</span> statusCode,
            PendingIntent requestIntent) {
        <span class="hljs-comment">// If removing the geofences was successful</span>
        <span class="hljs-keyword">if</span> (statusCode == LocationStatusCodes.SUCCESS) {
            <span class="hljs-comment">/*
             * Handle successful removal of geofences here.
             * You can send out a broadcast intent or update the UI.
             * geofences into the Intent's extended data.
             */</span>
        } <span class="hljs-keyword">else</span> {
        <span class="hljs-comment">// If adding the geocodes failed</span>
            <span class="hljs-comment">/*
             * Report errors here.
             * You can log the error using Log.e() or update
             * the UI.
             */</span>
        }
        <span class="hljs-comment">/*
         * Disconnect the location client regardless of the
         * request status, and indicate that a request is no
         * longer in progress
         */</span>
        mInProgress = <span class="hljs-keyword">false</span>;
        mLocationClient.disconnect();
    }
    ...
}
</code></pre>
<h3 id="-">移除特定的地理围栏</h3>
<p>移除个别地理围栏和地理围栏集合与移除所有地理围栏的过程类似。为了确定你要移除的地理围栏，需要将他们的地理围栏ID存储到一个字符串列表里面。将这个列表传给<code>removeGeofences</code>方法。这个方法接下来就可以启动这个移除过程了。</p>
<p>开始的时候要添加一个请求类型来申明这是一个删除里一个列表里面的地理围栏请求。同时还要全局变量来保存地理围栏的ID列表：</p>
<pre><code class="lang-java">...
    <span class="hljs-comment">// Enum type for controlling the type of removal requested</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">enum</span> REQUEST_TYPE = {ADD, REMOVE_INTENT, REMOVE_LIST}
    <span class="hljs-comment">// Store the list of geofence Ids to remove</span>
    String&lt;List&gt; mGeofencesToRemove;
</code></pre>
<p>接下来，定义一个你要移除的地理围栏列表。例如，下面的代码就移除了地理围栏ID为1的地理围栏：</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MainActivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FragmentActivity</span> <span class="hljs-keyword">implements</span>
        <span class="hljs-title">ConnectionCallbacks</span>,
        <span class="hljs-title">OnConnectionFailedListener</span>,
        <span class="hljs-title">OnAddGeofencesResultListener</span> {</span>
    ...
        List&lt;String&gt; listOfGeofences =
                Collections.singletonList(<span class="hljs-string">"1"</span>);
        removeGeofences(listOfGeofences);
    ...
}
</code></pre>
<p>下面的代码定义了<code>removeGeofences()</code>方法：</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MainActivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FragmentActivity</span> <span class="hljs-keyword">implements</span>
        <span class="hljs-title">ConnectionCallbacks</span>,
        <span class="hljs-title">OnConnectionFailedListener</span>,
        <span class="hljs-title">OnAddGeofencesResultListener</span> {</span>
    ...
    <span class="hljs-javadoc">/**
     * Start a request to remove monitoring by
     * calling LocationClient.connect()
     *
     */</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">removeGeofences</span>(List&lt;String&gt; geofenceIds) {
        <span class="hljs-comment">// If Google Play services is unavailable, exit</span>
        <span class="hljs-comment">// Record the type of removal request</span>
        mRequestType = REMOVE_LIST;
        <span class="hljs-comment">/*
         * Test for Google Play services after setting the request type.
         * If Google Play services isn't present, the request can be
         * restarted.
         */</span>
        <span class="hljs-keyword">if</span> (!servicesConnected()) {
            <span class="hljs-keyword">return</span>;
        }
        <span class="hljs-comment">// Store the list of geofences to remove</span>
        mGeofencesToRemove = geofenceIds;
        <span class="hljs-comment">/*
         * Create a new location client object. Since the current
         * activity class implements ConnectionCallbacks and
         * OnConnectionFailedListener, pass the current activity object
         * as the listener for both parameters
         */</span>
        mLocationClient = <span class="hljs-keyword">new</span> LocationClient(<span class="hljs-keyword">this</span>, <span class="hljs-keyword">this</span>, <span class="hljs-keyword">this</span>);
        <span class="hljs-comment">// If a request is not already underway</span>
        <span class="hljs-keyword">if</span> (!mInProgress) {
            <span class="hljs-comment">// Indicate that a request is underway</span>
            mInProgress = <span class="hljs-keyword">true</span>;
            <span class="hljs-comment">// Request a connection from the client to Location Services</span>
            mLocationClient.connect();
        } <span class="hljs-keyword">else</span> {
            <span class="hljs-comment">/*
             * A request is already underway. You can handle
             * this situation by disconnecting the client,
             * re-setting the flag, and then re-trying the
             * request.
             */</span>
        }
    }
    ...
}
</code></pre>
<p>当Location Services 调用这个回调函数说明这个连接成功，可以进行移除一个列表的地理围栏请求了。完成请求后就可以断开连接。例如：</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MainActivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FragmentActivity</span> <span class="hljs-keyword">implements</span>
        <span class="hljs-title">ConnectionCallbacks</span>,
        <span class="hljs-title">OnConnectionFailedListener</span>,
        <span class="hljs-title">OnAddGeofencesResultListener</span> {</span>
    ...
    <span class="hljs-keyword">private</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onConnected</span>(Bundle dataBundle) {
        ...
        <span class="hljs-keyword">switch</span> (mRequestType) {
        ...
        <span class="hljs-comment">// If removeGeofencesById was called</span>
            <span class="hljs-keyword">case</span> REMOVE_LIST :
                mLocationClient.removeGeofences(
                        mGeofencesToRemove, <span class="hljs-keyword">this</span>);
                <span class="hljs-keyword">break</span>;
        ...
        }
        ...
    }
    ...
}
</code></pre>
<p>定义 <a href="http://developer.android.com/reference/com/google/android/gms/location/LocationClient.OnRemoveGeofencesResultListener.html#onRemoveGeofencesByRequestIdsResult(int, java.lang.String[]" target="_blank">onRemoveGeofencesByRequestIdsResult()</a>方法的实现。 Location Services 调用这个方法的时候说明移除一个列表的地理围栏的请求已经完成了。在这个方法里面，检测得到的状态码并作出对应的动作：</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MainActivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FragmentActivity</span> <span class="hljs-keyword">implements</span>
        <span class="hljs-title">ConnectionCallbacks</span>,
        <span class="hljs-title">OnConnectionFailedListener</span>,
        <span class="hljs-title">OnAddGeofencesResultListener</span> {</span>
    ...
    <span class="hljs-javadoc">/**
     * When the request to remove geofences by IDs returns, handle the
     * result.
     *
     *<span class="hljs-javadoctag"> @param</span> statusCode The code returned by Location Services
     *<span class="hljs-javadoctag"> @param</span> geofenceRequestIds The IDs removed
     */</span>
    <span class="hljs-annotation">@Override</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">onRemoveGeofencesByRequestIdsResult</span>(
            <span class="hljs-keyword">int</span> statusCode, String[] geofenceRequestIds) {
        <span class="hljs-comment">// If removing the geocodes was successful</span>
        <span class="hljs-keyword">if</span> (LocationStatusCodes.SUCCESS == statusCode) {
            <span class="hljs-comment">/*
             * Handle successful removal of geofences here.
             * You can send out a broadcast intent or update the UI.
             * geofences into the Intent's extended data.
             */</span>
        } <span class="hljs-keyword">else</span> {
        <span class="hljs-comment">// If removing the geofences failed</span>
            <span class="hljs-comment">/*
             * Report errors here.
             * You can log the error using Log.e() or update
             * the UI.
             */</span>
        }
        <span class="hljs-comment">// Indicate that a request is no longer in progress</span>
        mInProgress = <span class="hljs-keyword">false</span>;
        <span class="hljs-comment">// Disconnect the location client</span>
        mLocationClient.disconnect();
    }
    ...
}
</code></pre>
<p>你可以将地理围栏同其他位置感知的特性结合起来，比如周期性的位置更新或者用户的活动识别。</p>
<p>下一课，<a href="activity-recognition.html">识别用户的活动状态</a>将会告诉你如何请求和接受活动更新。Location Services 会以一个正常的频率向你发送当前用户的身体活动信息。基于这些信息，你可以改变你的应用的一些行为。；例如，当你探测到用户由驾驶改为步行的时候，你可以把应用的信息更新频率设置为更长的时间。</p>

                    
                    </section>
                
                </div>
            </div>
        </div>

        
        <a href="../location/display-address.html" class="navigation navigation-prev " aria-label="Previous page: 显示位置地址"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../location/activity-recognition.html" class="navigation navigation-next " aria-label="Next page: 识别用户的当下活动"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/jsrepl/jsrepl.js" id="jsrepl-script"></script>
<script src="../gitbook/app.js"></script>

    
    <script src="http://cdn.mathjax.org/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-mathjax/plugin.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
